数据库中有的字段为null时,反馈到页面上是什么也不显示?如何用一个【无】字来代替呢?

<asp:ListView ID="listViewCustomer" DataSourceID="ods_Customer" runat="server"
DataKeyNames="CustomerId">
<EditItemTemplate>
<tr style="">
<td>
<asp:TextBox ID="FNameTextBox" runat="server" Text='<%# Bind("FName") %>' />
</td>
<td>
<asp:TextBox ID="FAddressTextBox" runat="server"
Text='<%# Bind("FAddress") %>' />
</td>
<td>
<asp:TextBox ID="FTelTextBox" runat="server" Text='<%# Bind("FTel") %>' />
</td>
<td>
<asp:TextBox ID="FFaxTextBox" runat="server" Text='<%# Bind("FFax") %>' />
</td>
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
未返回数据。</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="FNameLabel" runat="server" Text='<%# Eval("FName") %>' />
</td>
<td>
<asp:Label ID="FAddressLabel" runat="server" Text='<%# (Eval("FAddress").ToString() == string.Empty) ? "无" : Eval("FAddress") %>' />
</td>
<td>
<asp:Label ID="FTelLabel" runat="server" Text='<%# (Eval("FTel").ToString() == string.Empty) ? "无" : Eval("FTel") %>' />
</td>
<td>
<asp:Label ID="FFaxLabel" runat="server" Text='<%# Eval("FFax").ToString() == string.Empty ? "无" : Eval("FFax") %>' />
</td>
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="删除" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="编辑" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
FName</th>
<th runat="server">
FAddress</th>
<th runat="server">
FTel</th>
<th runat="server">
FFax</th>
<th id="Th1" runat="server">
</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>

  主要是看ItemTemplate部分,另外值得一提的是编辑模板不要改动,那样会正常的更新回数据库

上一篇:iOS对象属性详解


下一篇:LeetCode算法题-Second Minimum Node In a Binary Tree(Java实现)