asp.netcommandfield

Set CommandField Select Visibilty from aspx page


I want to do something like this with a GridView:

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

But that doesn't work, coming up with error:

Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.CommandField does not have a DataBinding event.

Is there anyway I can set the visibility from the aspx page? PS: SC_TABLE exists from the datasource, so nothing wrong from that part.


Solution

  • You could do this with a TemplateField instead...

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