【发布时间】:2016-10-26 20:59:45
【问题描述】:
这是templatefield,即Gridview 中的第10 列:
<asp:TemplateField>
<HeaderTemplate>
<asp:Label runat="server">Active Licenses</asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblActiveCodes" runat="server" Text='intValues'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
这是在foreach 循环中引用它的地方。
foreach (GridViewRow row in gvCustomers.Rows)
{
if (row.Cells[10].Text.Equals(0))
{
row.Visible = false;
}
}
所以它是GridView 中的第 10 列,我希望使值为 0 的单元格不可见。 intValues 是 int,来自数据库。 gvCustomers 是我的GridView 的ID。
为什么row.Cells[10] 不起作用,但更重要的是,我们怎样才能使它起作用?
【问题讨论】:
-
您可以像这样设置
Visible属性Visible='<%#GetVisible(Eval("intValues ").ToString())%>'然后在后面代码的GetVisible方法中检查它是否等于0,然后返回false。检查我 7 小时前回答的这个问题会对您有所帮助:stackoverflow.com/questions/40263845/…