Use of the pagination function provided by gridview

Source: Internet
Author: User

Gridview has its own paging function, but an error occurred when I used it today.

Error:The data source does not support server-side data paging.

Later I found it onlineSqldatareader does not support paging.Replace sqldataadapter and dataset,CodeAs follows.

  Public Dataset getalluserinfo ()
{
Sqlconnection myconnection = New Sqlconnection (
Configurationmanager. connectionstrings [ " Emergencyhandlingdbconnectionstring " ]. Connectionstring );

Sqlcommand mycommand = myconnection. createcommand (); // CREATE Command
Mycommand. commandtype = commandtype. storedprocedure; // Specify to execute stored procedure operations
Mycommand. commandtext = " Getuserinfo " ; // Stored Procedure name

// Define datereader
// Sqldatareader DR = NULL;

Sqldataadapter da = New Sqldataadapter (mycommand );
Dataset DS = New Dataset ();
Da. Fill (DS );
Try
{
// Myconnection. open ();


// Read data
// Dr = mycommand. executereader (commandbehavior. closeconnection );
}
Catch (Sqlexception ex)
{
Throw New Exception (ex. Message, ex );
}

Return DS;
}

Protected Void Page_load ( Object Sender, eventargs E)
{
If (! Ispostback)
{
Bindgrid ();
}
}

Protected Void Bindgrid ()
{
Dataset DS = user. getalluserinfo ();
// Sqldatareader DR = user. getalluserinfo ();

Usermanagegridview. datasource = Ds;
Usermanagegridview. databind ();

// Dr. Close ();
}

No error was reported after the replacement, but an error was reported when the page was turned over...

Error:The gridview 'usermanagegridview 'fired event pageindexchanging which wasn' t handled.

Check again and find that the pageindexchanging time is not processed, and then add the following code to finally run normally.

 
Protected VoidUsermanagegridview_pageindexchanging (ObjectSender, gridviewpageeventargs E)
{
Usermanagegridview. pageindex = E. newpageindex;
Bindgrid ();
}

There are so many things to learn. It is a big problem for new users who have minor problems!

A long journey ......

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.