开发者

strange GridView issue: 2 rows selected and nonexistent RowState of 3

i have a strange problem. In RowCreated of the GridVi开发者_高级运维ew 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:

  If LblPrimaryKey.Text.Equals(Me.CurrentID) Then
     Me.MainGrid.SelectedIndex = e.Row.RowIndex
  End If

Now i only save the new selectedIndex in a variable and set it after this:

  If LblPrimaryKey.Text.Equals(Me.CurrentID) Then
     selectedIndex = e.Row.RowIndex 'member variable'
     'Me.MainGrid.SelectedIndex = e.Row.RowIndex'
  End If

And after RowDataBound in the function that called DataBind:

  Me.MainGrid.DataBind()
  Me.MainGrid.SelectedIndex = Me.selectedIndex

Now all old selections are cleared and only one row is selected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜