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>

解决方案 »

  1.   

    或者自定义sql:
    select nvl(字段,"空") from table 
      

  2.   


    <!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>
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(string));
            dt.Columns.Add("Name", typeof(string));
            DataRow dr = null;
            for (int i = 0; i < 5; i++)
            {
                dr = dt.NewRow();
                dr["ID"] = i.ToString();
                dr["Name"] = "Name" + i.ToString();
                dt.Rows.Add(dr);
            }        dr = dt.NewRow();
            dr["ID"] ="10";
            dr["Name"] = "";
            dt.Rows.Add(dr);
            DataList1.DataSource = dt;
            DataList1.DataBind();
        }
        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Label lable = e.Item.FindControl("Name") as Label;
            string strName = DataBinder.Eval(e.Item.DataItem, "Name").ToString();
            if (string.IsNullOrEmpty(strName))
            {
                strName = "空了";
            }
            lable.Text = strName;
        }
      

  3.   

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

  4.   

    那上面是重新添加列吗    我已经绑定了datalist1了   就是当查出来没数据时  绑定字段  怎么显示我需要的
      

  5.   

    这是SQL语句   select top 9 Users.*,ADBook.* from Users,ADBook where Users.userId=ADBook.userId and showdate=@showdate order by price desc