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>
我想在前台判断 如果字段为空 要给绑定的字段 赋其它指定的值 怎么处理根据特定条件 查出来所有字段都没数据 用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>
解决方案 »
- 高手来解释一下,数据库的几个概念。
- 请问一个鼠标经过gridview改变行颜色的问题
- 求救高手 asp.net2.0下邮件发送问题???
- 在线等!!!!删除服务器文件夹是提示“正由另一进程使用,因此该进程无法访问该文件”急!!!!!!!!!
- 求 20个页面美观的网站!
- 初学索引器
- 高分求ASP.NET实现手机话费查询实例代码(高手请进)
- 求示例代码:检查一组值是否在数据库中,如果存在忽略,如果不存在加入,如果数据库多余删除
- 如何把DataGrid控件的全部功能绑定到DropDownList的下拉框下?
- asp.net2.0 小鸟报警是110的过来看看
- 打开数据库效率问题
- 自定义类中为何无法使用System.Web.Caching
select nvl(字段,"空") from table
<!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;
}