Asp. NET component DataGrid's pagination practical method

Source: Internet
Author: User
asp.net|datagrid| Paging

Check online data, about this DataGrid paging is too many methods, some solutions are too trick, some are inefficient, here provides a less cumbersome, but also efficient (through the session cache DataSet) method:

Drag the DataGrid to WebForms, select columns from the DataGrid's property bar to open the DataGrid Properties Customization dialog box, select paging pagination, Allow paging, page size:20.

private void Page_Load (object sender, System.EventArgs e)
{
Put user code to initialize the page here
if (!this. IsPostBack)
{
SqlDataAdapter1.Fill (DATASET11);
session["Copyyear"]=DATASET11;
DataGrid1.DataSource = Dataset11.tables[0]. DefaultView;
Datagrid1.databind ();
}
}
private void Datagrid1_pageindexchanged (object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
Datagrid1.currentpageindex=e.newpageindex;
dataset11= (DATASET1) session["Copyyear"];
DataGrid1.DataSource = Dataset11.tables[0]. DefaultView;
Datagrid1.databind ();
}

Add the above code on the page, OK



Related Article

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.