从设置aspx页面CommandField中选择能见度
-
16-09-2019 - |
题
我想要做这样的事情有一个GridView:
<asp:CommandField ShowSelectButton="True" Visible='<%# return Eval("SC_TABLE") %>' />
但是,这并不工作,未来与错误:
数据绑定表达式仅 支持对具有对象 DataBinding事件。 System.Web.UI.WebControls.CommandField 不具有数据绑定事件。
反正我有可以设置从aspx页面的知名度? PS:SC_TABLE从数据源存在,所以没有错从该部分
。解决方案
您可以用一个TemplateField做到这一点,而不是...
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID=SelectButton CommandName="SELECT" Visible='<%# Eval("SC_TABLE") %>' Text="Select" />
</ItemTemplate>
</asp:TemplateField>
其他提示
我发现在此帖子的端部的答案:
基本上,你需要捕获RowCreated事件上的数据网格
OnRowCreated = “GridView1_RowCreated”
然后,aspx.cs页面上使用以下代码来隐藏控件:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 1)
{
e.Row.Cells[0].Controls.Clear();
}
}
如果您在第一列一个CommandField它的工作原理。
不隶属于 StackOverflow