Question

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.

Was it helpful?

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>

OTHER TIPS

I found the answer at the end of this post:

Basically, you need to capture the RowCreated event on the DataGrid

OnRowCreated="GridView1_RowCreated"

Then, on the aspx.cs page use the following code to hide controls:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowIndex == 1)
    {
        e.Row.Cells[0].Controls.Clear();
    } 
}

It works if you have a CommandField in the first column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top