hidura
hidura

Reputation: 693

GridView.SelectedIndexChanged doesn't fire

Hello i have a gridview that is connected to the event selectedindexchanged and is on a hidden panel but when i try to fire the event don't do anything. This is the code of the gridview:

<asp:GridView ID="GridView1" runat="server" CssClass="mGrid" 
                    Width="847px" onselectedindexchanged="GridView1_SelectedIndexChanged2">
                    <Columns>
                        <asp:ButtonField Text="Borrar" />
                    </Columns>
                </asp:GridView>

This is the code on the event:

protected void GridView1_SelectedIndexChanged2(object sender, EventArgs e)
{
    GridViewRow row = GridView1.SelectedRow;
    Response.Write(row.Cells[2].Text);
}

Upvotes: 0

Views: 692

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67938

That's because that button isn't a SelectButton, one approach would be to set the AutoGeneratesSelectButton property on the GridView to true. You could then get rid of that other button you're trying to make work.

If you need that other button then you'll need to make it a CommandField and set the ShowSelectButton to true. With that configuration you can set the SelectText and have some custom text for the button.

Either way, a Button isn't going to do anything for SelectedIndexChanged.

Upvotes: 2

Related Questions