开发者

Datagrid Page index changed

I have a 开发者_开发百科Datagrid on ASP.NET web form which I have bound to a data source and set it to have 10 records per page. I also have a hyper link column on the Datagrid , such that a user can navigate to another page (details page) from the list. On the details page, they have "Cancle" button to return to the Datagrid page

I am looking for sample code snippet on the Server Side on how to specify the page index to set the Datagrid after data binding. The idea is to ensure the user navigates to the same page index they were on.


Instead of using the Session, you could also use the QueryString-param of the ID of the currently selected record(that one you wanted to show on the detail-page). Pass it back to the GridView-Page and add functionality to find it in the Grid and set the PageIndex accordingly.

Something like this:

Dim dr As DataRow = MyDataTble.Rows.Find(Request.QueryString("ID"))
Dim selectedIndex As Int32 = Me.GridView1.Find(dr.MySortColumn)
Dim pageIndexofSelectedRow As Int32 = CInt(Math.Floor(selectedIndex / Me.GridView1.PageSize))

If pageIndexofSelectedRow < 0 Then
   Me.GridView1.PageIndex = 0
   Me.GridView1.SelectedIndex = -1
Else
  Me.GridView1.PageIndex = pageIndexofSelectedRow
  Me.GridView1.SelectedIndex = selectedIndex Mod Me.GridView1.PageSize
End If
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜