Here is an interesting puzzle. I have a DataGrid whose Select function causes a new record to be inserted in a database with the data from the selected item, then fills a different DataGrid with the updated data. Once this is accomplished, I set the selected
item in the second DataGrid to be the new item, so the same data is highlighted in both grids and the user can see what they've added. This works perfectly *except* when the new item is to be the first on a new page in the second grid. In that case, the selected
item is the last item on the page *before* the last page. If you add one more item, the behavior returns to normal and you can see that the first item on the new page was added correctly, just not displayed properly. To make matters even more perplexing, in
the case where an insert has created a new page, if you click the Next button to view the last page it displays the top item from the next to last page! Adding another item then sorts it out as before. Anyone have a clue what might cause this??? Here is the
pertinent code:
linuxchiq
Member
95 Points
19 Posts
DataGrid paging off by one when adding new item
Dec 11, 2003 07:46 PM|LINK
protected void dgrFunction_SelectedIndexChanged(object sender, System.EventArgs e) { addJobCodeFnc(); FillJobCodeFncFresh(); if(dgrJobCodeFunction.PageCount > 0) { dgrJobCodeFunction.CurrentPageIndex = (dgrJobCodeFunction.PageCount - 1); } dgrJobCodeFunction.SelectedIndex = (dgrJobCodeFunction.Items.Count - 1); FillExpectationFncFresh(); }