1

我想用 GridView 做这样的事情:

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

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

只有具有 DataBinding 事件的对象才支持数据绑定表达式。System.Web.UI.WebControls.CommandField 没有 DataBinding 事件。

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

4

2 回答 2

3

你可以用 TemplateField 来代替......

<asp:TemplateField>
    <ItemTemplate>
        <asp:LinkButton runat="server" ID=SelectButton CommandName="SELECT" Visible='<%# Eval("SC_TABLE") %>' Text="Select" />
    </ItemTemplate>
</asp:TemplateField>
于 2009-07-16T15:01:35.740 回答
1

我在这篇文章的最后找到了答案:

基本上,您需要在 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,它会起作用。

于 2010-07-27T19:47:24.707 回答