开发者

Selected value not changing when Gridview is re-ordered

When I select a row from my gridview by clicking on a linkbutton called 'Modify' and is the last cell in the row. Using the code below I can retrieve the key value from within the GridView1_RowCommand sub and move to the modify screen with the correct data.

    Dim r As Integer = e.CommandArgument        
    GridView1.SelectedIndex = r
    Dim Company As String = GridView1.SelectedDataKey(0).ToString
    ModifyDetail(Company)

However if I re-order the Gridview from a search option as below

    SqlDataSource.SelectCommand = NewSearchStr
    GridView1.DataBind()

When I try to access the first row it returns the first row value from 开发者_如何学Cthe original Gridview and not from the re-ordered one. What am I missing?


I believe this is a persistence issue. SelectCommand is not persisted in ViewState for security reasons, so you may have to persist and assign the DataSource to NewSearchStr each time the Grid is initialized.

see VB Gridview selects wrong row for editing

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜