. Net high-efficiency Distributed Solution (substitution)

Source: Internet
Author: User

Private void page_load (Object sender, system. eventargs E)
{
This. btnpreviouspage. Click + = new system. eventhandler (this. navigatetopage );
This. btnnextpage. Click + = new system. eventhandler (this. navigatetopage );
If (! Ispostback)
{
Startindex = 0;
Sqlconnection myconnection = new sqlconnection ("Data Source = NGB-INTRATST-1; user id = winc; Password = 123; initial catalog = winc ;");
Sqlcommand mycommand = new sqlcommand ("select num = count (*) from authors", myconnection );
Myconnection. open ();
Sqldatareader DR = mycommand. executereader (commandbehavior. singlerow );

If (dr. Read ())
Mydatagrid. virtualitemcount = (INT) Dr ["num"];

Dr. Close ();
Myconnection. Close ();
Bindgridtosource (startindex, "previous shard ");
}
}

------------------------------------------------------------------

Private void bindgridtosource (INT startposition, string gotopage)
{
Sqlconnection myconnection = new sqlconnection ("Data Source = NGB-INTRATST-1; user id = winc; Password = 123; initial catalog = winc ;");
Sqlcommand mycommand = NULL;
Switch (gotopage)
{
Case "previous example ":
Mycommand = new sqlcommand ("select top 5 au_id, au_lname, au_fname," +
"Phone, address, city, state, zip, contract from authors" + "+
"Where au_id >=@ uid order by au_id", myconnection );

If (startposition = 0)
Mycommand. Parameters. Add ("@ uid", sqldbtype. nvarchar, 4). value = "0 ";
Else
Mycommand. Parameters. Add ("@ uid", sqldbtype. nvarchar, 4). value =
Viewstate [(mydatagrid. currentpageindex + 1). tostring ()];
Break;

Case "next cursor ":
Mycommand = new sqlcommand ("select top 5 au_id, au_lname, au_fname," +
"Phone, address, city, state, zip, contract from authors" + "+
"Where au_id> @ uid order by au_id", myconnection );
Mycommand. Parameters. Add ("@ uid", sqldbtype. nvarchar, 4). value =
Mydatagrid. items [4]. cells [0]. text;

Break;
}

Myconnection. open ();

Sqldatareader DR = mycommand. executereader ();
Mydatagrid. datasource = Dr;
Mydatagrid. databind ();
Dr. Close ();
Myconnection. Close ();

Viewstate [(mydatagrid. currentpageindex + 1). tostring ()] =
Mydatagrid. items [0]. cells [0]. text;
}

-----------------------------------------------------------------------

Public void navigatetopage (Object sender, system. eventargs E)
{
String pageinfo = (button) sender). commandname;
Switch (pageinfo)
{
Case "previous example ":
If (mydatagrid. currentpageindex> 0)
Mydatagrid. currentpageindex-= 1;
Else
Return;
Break;
 
Case "next cursor ":
If (mydatagrid. currentpageindex <(mydatagrid. pagecount-1 ))
Mydatagrid. currentpageindex + = 1;
Else
Return;
Break;
}

Startindex = mydatagrid. currentpageindex * mydatagrid. pagesize;
Bindgridtosource (startindex, pageinfo );

}

 

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.