读书人

各位!

发布时间: 2012-02-06 15:52:44 作者: rapoo

各位大虾救命啊!!!
datalist 绑定了字段 如果在后台查询的所有字段都为空 包括绑定的字段也为空
我想在前台判断 如果字段为空 要给绑定的字段 赋其它指定的值 怎么处理

根据特定条件 查出来所有字段都没数据 用System.DBNull.Value判断行吗? 还是System.DBNull.Value 判断的是有记录 主键及其它一些字段 而绑定的字段为空 才有用

<asp:DataList ID="DataList1" runat="server" DataKeyField="adbookId"
RepeatColumns="3" RepeatDirection="Horizontal">
<ItemTemplate>
<div id="content">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 360px; text-align: center;">
<a href="#">
<img src='<%#("imagepath")==System.DBNull.Value ?"空时显示的值":"不为空时显示的值" %>' alt="" />
</a>
</td>
</tr>
<tr>
<td style="width: 360px; text-align: center;">
<a href="#">
<%#Eval("price")==System.DBNull.Value ?"空时显示的值":"不为空时显示的值"%>古币 </a>
<asp:Label ID="Label4" runat="server" Text='<%#Eval("price")%>' Visible="false"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 360px; text-align: center;">
<a href="#">
<%#Eval("userName")==System.DBNull.Value ?"空时显示的值":"不为空时显示的值"%>领先 </a>
</td>
</tr>
<tr>
<td style="width: 360px; text-align: center;">
<asp:LinkButton ID="lbBight" runat="server">我要竞拍</asp:LinkButton>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:DataList>

[解决办法]
在databound中判断最好
[解决办法]
或者自定义sql:
select nvl(字段,"空") from table
[解决办法]

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">        <asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">            <ItemTemplate>                <asp:Label ID="Name" runat="server"></asp:Label>            </ItemTemplate>        </asp:DataList>    </form></body>

[解决办法]

探讨

page_load里的是什么意思啊 解释下 查出来的表字段没有任何值 想让一些字段显示我想要的值 谢谢引用:
HTML code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xht……

读书人网 >asp.net

热点推荐