【问题标题】:Set CommandField Select Visibilty from aspx page设置 CommandField 从 aspx 页面中选择 Visibilty
【发布时间】:2009-07-16 14:50:39
【问题描述】:

我想用 GridView 做这样的事情:

<asp:CommandField ShowSelectButton="True" Visible='<%# return Eval("SC_TABLE") %>' />

但这不起作用,出现错误:

数据绑定表达式仅 支持具有 数据绑定事件。 System.Web.UI.WebControls.CommandField 没有 DataBinding 事件。

无论如何我可以从 aspx 页面设置可见性吗? PS:SC_TABLE 存在于数据源中,因此该部分没有任何问题。

【问题讨论】:

    标签: asp.net commandfield


    【解决方案1】:

    您可以使用 TemplateField 来代替...

    <asp:TemplateField>
        <ItemTemplate>
            <asp:LinkButton runat="server" ID=SelectButton CommandName="SELECT" Visible='<%# Eval("SC_TABLE") %>' Text="Select" />
        </ItemTemplate>
    </asp:TemplateField>
    

    【讨论】:

    • +1:我希望用 CommandField 来实现。我已经知道这种方式,但它仍然有帮助。哦,好吧,CommandField 似乎是不可能的。 :(
    • 除非其他人能提供更好的答案,否则我会在几天后将此答案标记为已接受。
    【解决方案2】:

    我在this post的末尾找到了答案:

    基本上,您需要在 DataGrid 上捕获 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,它就可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      相关资源
      最近更新 更多