首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

急GridView的一个有关问题

2012-01-31 
急,在线等,GridView的一个问题用GridView显示数据,现在从数据库中读出来的一个字段值是是0或1,那么现在如

急,在线等,GridView的一个问题
用GridView显示数据,现在从数据库中读出来的一个字段值是是0或1,那么现在如果是0我想显示“否”,如果是1想显示成“是”!
各位朋友,帮个忙啊!!!
谢谢!!

[解决办法]
或者直接在GridView里写

<asp:TemplateField HeaderText="列标题">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("字段").ToString()="0" ? "否":"是"'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
[解决办法]
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="False" DataKeyNames="F_ID" DataSourceID="sqlLink" AllowPaging="True" OnRowEditing="gvList_RowEditing" Width="100%">
<Columns>
<asp:BoundField DataField="Title" HeaderText="链接标题" SortExpression="Title" />
<asp:BoundField DataField="Link" HeaderText="链接地址" SortExpression="Link" />
<asp:BoundField DataField="Target" HeaderText="链接方式" SortExpression="Target" />
<asp:TemplateField HeaderText="审核" SortExpression="Status">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Status").ToString() == "1" ? "已审核" : "未审核" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="End_Date" HeaderText="到期日期" SortExpression="End_Date" DataFormatString="{0:yyyy年MM月dd日}" HtmlEncode="False" />
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqlLink" runat="server" ConnectionString="<%$ ConnectionStrings:WebSiteDB %>" SelectCommand="SELECT * FROM [Link]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
[解决办法]

C# code
protected void GridView1_DataBound(Object sender, GridViewRowEventArgs e)    {            for(int i=0;i<GridView1.Rows.Count;i++)            {                 GridView1.Rows[i].Cells[列索引].Text= GridView1.Rows[i].Cells[列索引].Text ==0?"否":"是";            }    } 

热点排行