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 ......