Last post Sep 13, 2006 10:41 PM by codeasp
Sep 13, 2006 07:36 PM|Brito|LINK
I have a GridView with a linkbuton (on each row) that calls another page with a DetailsView, where users can edit the record.
But let's say when the GridView was opened it had 7 pages and i was on the page 4, how after edit the record on the DetailsView can i go back to the GridView opening it on the same page?
If i use server.transfer("list.aspx") the GridView always starts on the first page.
Sep 13, 2006 09:44 PM|codeasp|LINK
When you transfer the page, the page is recreated, so it will start from the first page. One option is when you are opening the DetailsView page for editing send a variable which keeps track of the page where the record was in the Grid. In the grid page
(list.aspx) check for the variable (let's say pageno) and if it exists the set the Grid's PageIndex property to be the pageno variable else defaults to 0.
Though I would caution against this, because if there is lot of entries to the base table then your record might not be in the same page as in the beginning. Example: when user A starts at list.aspx, record 10 is on page 2, but when he returns (because
of other users changing/adding) the record 10 might have been of page 3. Hope I haven't confused you.
Sep 13, 2006 09:53 PM|Brito|LINK
Thanks for your help.
I will check the Grid's PageIndex property out.
But what you just said about other people changing/adding records is very important.
In this case, i'll have to find in which page the record actually is and after that, set the Grid's PageIndex property.
Now the question is... is that possible?
Sep 13, 2006 10:41 PM|codeasp|LINK
Well I think so, but will it be feasible is another question altogether. To achieve the following solution, you need to have DataTable as your datasource.
1. If the PageNo variable does not exist, just bind the datatable as the datasource to the GridView (assuming you have a GridView - will also work with DataGrid, DataList etc.)
2. If the PageNo variable exist, then add a DataColumn to the DataTable. The newly added datacolumn must have the following properties set.
Dim column As DataColumn = New DataColumn
column.DataType = System.Type.GetType("System.Int32")
.ColumnName = "NewID"
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
3. Use the Select method of the DataTable to get the record.
Dim foundRows() As DataRow
foundRows = table.Select("ID = " & RecordToBeFound)
' If found then get the NewID
if foundRows.Count > 0 then
dim foundNewID as integer = cint(foundrows(0)(0))
dim pIndex as integer = cint(foundNewID / Gv1.PageSize)
GV1.PageIndex = pIndex