First, analyze the cause:
1. Bind datakeynames.
2. Sort the records and assign the index number, starting from 0.
3. When other pages are clicked, The gridview will reassign count to the number of records on the current page.
Eg: two entries are displayed on each page, five in total, that is, three pages.
Page 1, gridview. Count is 2
Page 2, gridview. Count is also 2
Page 3, gridview. Count is 1
That is to say, count is the number of pages. E. commandargument index numbers are incremental and are not re-allocated.
Solution:
Int ipageindex = gridview1.pageindex; // obtain the index of the current page.
Int ipagesize = gridview1.pagesize; // obtain the number of records displayed on each page
Int iindex = convert. toint16 (E. commandargument)-ipageindex * ipagesize; // calculate
String Strid = gridview1.datakeys [iindex]. value. tostring ();
// Obtain the ID, whether it is deleted or updated, as needed.