Stored Procedure of Self-writing pagination in gridview

Source: Internet
Author: User

I wrote a paging storage process two days ago. Today I also wrote the front-end and posted the code to share with you. Please kindly advise me ~

<Asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "false" cellpadding = "4"
Forecolor = "#333333" gridlines = "NONE" width = "650px" onrowcancelingedit = "gridview1_rowcancelingedit"
Onrowdeleting = "gridview1_rowdeleting" onrowediting = "gridview1_rowediting" onrowupdating = "gridview1_rowupdating"
Footerstyle-backcolor = "#990000" font-bold = "true" datakeynames = "userid" onrowdatabound = "gridview1_rowdatabound">
<% -- <Pagertemplate>
<Asp: linkbutton id = "lbfirst" runat = "server" causesvalidation = "false"> first </ASP: linkbutton>
<Asp: linkbutton id = "lbprev" runat = "server" causesvalidation = "false"> Prev </ASP: linkbutton>
<Asp: linkbutton id = "lbnext" runat = "server" causesvalidation = "false"> next </ASP: linkbutton>
<Asp: linkbutton id = "lblast" runat = "server" causesvalidation = "false"> last </ASP: linkbutton>
Page <asp: Label id = "lbcurpage" runat = "server" text = ""> </ASP: Label>
Total <asp: Label id = "lbpagecount" runat = "server" text = ""> </ASP: Label> pages
Jump to <asp: textbox id = "tbpage" runat = "server" text = "" width = "27px"> </ASP: textbox>
<Asp: linkbutton id = "LBGO" runat = "server" causesvalidation = "false" text = "go"> </ASP: linkbutton>
</Pagertemplate> -- %>
<Columns>
<Asp: boundfield datafield = "userid" headertext = "userid" readonly = "true"/>
<Asp: boundfield datafield = "username" headertext = "username"/>
<Asp: boundfield datafield = "userpwd" headertext = "userpwd"/>
<% -- <Asp: boundfield datafield = "gender" headertext = "gender"/> -- %>
<Asp: templatefield headertext = "gender">
<Edititemtemplate>
<Asp: dropdownlist id = "gender" runat = "server">
</ASP: dropdownlist>
</Edititemtemplate>
<Itemtemplate>
<% # Eval ("gender") %>
</Itemtemplate>
</ASP: templatefield>
<Asp: boundfield datafield = "phonenumber" headertext = "phonenumber"/>
<Asp: boundfield datafield = "Address" headertext = "Address"/>
<Asp: commandfield headertext = "select" showselectbutton = "true"/>
<Asp: commandfield headertext = "edit" showeditbutton = "true"/>
<Asp: commandfield headertext = "delete" showdeletebutton = "true"/>
</Columns>
<Rowstyle forecolor = "#000066" type = "regxph" text = "yourobjectname"/>
<Selectedrowstyle backcolor = "#669999" font-bold = "true" forecolor = "white"/>
<Pagerstyle backcolor = "white" forecolor = "#000066" horizontalalign = "Left"/>
<Headerstyle backcolor = "#006699" font-bold = "true" forecolor = "white"/>
</ASP: gridview>
<Asp: linkbutton id = "lbfirst" runat = "server" causesvalidation = "false"
Onclick = "lbfirst_click"> first </ASP: linkbutton>
<Asp: linkbutton id = "lbprev" runat = "server" causesvalidation = "false"
Onclick = "lbprev_click"> Prev </ASP: linkbutton>
<Asp: linkbutton id = "lbnext" runat = "server" causesvalidation = "false"
Onclick = "lbnext_click"> next </ASP: linkbutton>
<Asp: linkbutton id = "lblast" runat = "server" causesvalidation = "false"
Onclick = "lblast_click"> last </ASP: linkbutton>
Page <asp: Label id = "lbcurpage" runat = "server" text = ""> </ASP: Label>
Total <asp: Label id = "lbpagecount" runat = "server" text = ""> </ASP: Label> pages
Jump to <asp: textbox id = "tbpage" runat = "server" text = "" width = "27px"> 1 </ASP: textbox>
<Asp: linkbutton id = "LBGO" runat = "server" causesvalidation = "false" text = "go"> </ASP: linkbutton>

 

The following is the background code,

 

/// // Start with Data Binding ///////////// //////////////////////////////////////// //

Protected void gridview_bind ()
{
Try
{
Lbcurpage. Text = "1 ";
User_managementbll umb = new user_managementbll ();
Arraylist Al = umb. gridviewpage (lbcurpage. Text, "2 ");
Lbpagecount. Text = convert. tostring (Al [1]);
Gridview1.datasource = (Dataset) al [0];
Gridview1.databind ();
}
Catch (exception ex)
{

Throw ex;
}
}

/// // The first page /// ////////////////////////////////////////

Protected void lbfirst_click (Object sender, eventargs E)
{
Try
{
Lbcurpage. Text = "1 ";
User_managementbll umb = new user_managementbll ();
Arraylist Al = umb. gridviewpage (lbcurpage. Text, "2 ");
Lbpagecount. Text = convert. tostring (Al [1]);
Gridview1.datasource = (Dataset) al [0];
Gridview1.databind ();
}
Catch (exception ex)
{

Throw ex;
}
}

 

/// // Previous Page ///////// ///////////////////////////////////
Protected void lbprev_click (Object sender, eventargs E)
{
Try
{
If (lbcurpage. Text = "1 ")
{
Lbcurpage. Text = "1 ";
User_managementbll umb = new user_managementbll ();
Arraylist Al = umb. gridviewpage (lbcurpage. Text, "2 ");
Lbpagecount. Text = convert. tostring (Al [1]);
Gridview1.datasource = (Dataset) al [0];
Gridview1.databind ();
}
Else
{
Lbcurpage. Text = convert. tostring (convert. toint32 (lbcurpage. Text)-1 );
User_managementbll umb = new user_managementbll ();
Arraylist Al = umb. gridviewpage (convert. tostring (convert. toint32 (lbcurpage. Text)-1), "2 ");
Lbpagecount. Text = convert. tostring (Al [1]);
Gridview1.datasource = (Dataset) al [0];
Gridview1.databind ();
}

}
Catch (exception ex)
{

Throw ex;
}
}

 

/// // Next page //////// /////////////////////////////////////
Protected void lbnext_click (Object sender, eventargs E)
{
Try
{
Lbcurpage. Text = convert. tostring (convert. toint32 (lbcurpage. Text) + 1 );
User_managementbll umb = new user_managementbll ();
Arraylist Al = umb. gridviewpage (convert. tostring (convert. toint32 (lbcurpage. Text)-1), "2 ");
Lbpagecount. Text = convert. tostring (Al [1]);
Gridview1.datasource = (Dataset) al [0];
Gridview1.databind ();
}
Catch (exception ex)
{

Throw ex;
}
}

 

/// // The last page ////////////////////// ////////////////////////////////
Protected void lblast_click (Object sender, eventargs E)
{
Try
{
Lbcurpage. Text = lbpagecount. text;
User_managementbll umb = new user_managementbll ();
Arraylist Al = umb. gridviewpage (convert. tostring (convert. toint32 (lbpagecount. Text)-1), "2 ");
Lbpagecount. Text = convert. tostring (Al [1]);
Gridview1.datasource = (Dataset) al [0];
Gridview1.databind ();
}
Catch (exception ex)
{

Throw ex;
}
}

 

/// // BLL layer /////// ///////////////////////////////////////

Public class user_managementbll
{
Public user_managementbll ()
{
//
// Todo: Add constructor logic here
//
}

Public arraylist gridviewpage (string curpage, string pagezize)
{
User_managementdal UMD = new user_managementdal ();
Arraylist Al = UMD. gridviewpagedal (curpage, pagezize );
Return al;
}

 

}

//// // Dal layer //////////////////////// //////////////////////////////

Public class user_managementdal
{
Public user_managementdal ()
{
//
// Todo: Add constructor logic here
//
}

Public arraylist gridviewpagedal (string curpage, string pagezize)
{
String proc_name = "[Kiros]. [static_user_page]";
Dataset DS = new dataset ();
Sqlparameter [] Params = new sqlparameter [3];
Params [0] = new sqlparameter ("@ curpageindex", "0 ");
Params [1] = new sqlparameter ("@ pagesize", "2 ");
Params [2] = new sqlparameter ("@ pagecount", sqldbtype. varchar, 10 );
Params [2]. Direction = parameterdirection. output;

Mydbhelper Kiros = new mydbhelper ();
Arraylist Al = Kiros. proc_excute_arraylist (proc_name, Params );
DS = (Dataset) al [0];
Return al;
}
}

 

Please kindly advise if you have any suggestions.

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.