开发者

Selected value not changing when Gridview is re-ordered

开发者 https://www.devze.com 2023-03-27 22:12 出处:网络
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_RowComma

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

精彩评论

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