Rowcommand error after gridview pagination: Index out of range

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.