i have a strange problem.
In RowCreated of the GridView i add following script to select a row:
Select Case e.Row.RowType
Case DataControlRowType.DataRow
e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(Me.MainGrid, "Select$" & e.Row.RowIndex)
End Select
This works like a charm(i thought).
But when i debug the SelectedIndexChanging and the following SelectedIndexChanged events, i observe that the RowState of the selected Row switches from normal{0}/alternate{1} to 3 instead of selected{2}.
This occurs between SelectedIndexChanging and SelectedIndexChanged.
Why does this happen?
The next time i programmatically set the selectedIndex(f.e. after a new row was created), i have two rows that are selected and no (un-hacky) way to deselect the old in RowDataBound, because of the invalid RowState of 3(should only be 0,1,2,4 or 8).
Thank you.
I still don’t know why the RowState changes to 3, but i have a solution for the multiple selected rows. So far i set the GridView.SelectedIndex in RowDataBound:
Now i only save the new selectedIndex in a variable and set it after this:
And after RowDataBound in the function that called DataBind:
Now all old selections are cleared and only one row is selected.