views:

579

answers:

1

I want the gridview SelectedRowStyle and EditRowStyles to be mutually exclusive so that the edit-row style is turned off when another row is selected and the selected-row style is turned off when another row is put in editing mode. I tried handling OnRowEditing and changing the CssClass for the currently selected row, but that didn't work.

Thanks!

+1  A: 

Are you saying you want selection and editing to be mutually exclusive? If so, this should work if you're using the usual command buttons (autogenerate edit, autogenerate select).

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        GridView1.EditIndex = -1;
    }
    else if (e.CommandName == "Edit")
    {
        GridView1.SelectedIndex = -1;
    }
}
Nikki9696
Good solution! I just hit on this myself after making my last comment, but props to you.
Bob_Kruger