Asp. Implementation of custom DataGrid paging settings in net

Source: Internet
Author: User
Tags prev trim

Here I realized the DataGrid personalized paging, now put the code out Friends reference, at the same time in the realization of this function process, reference to the "flying knife" from abroad to translate an article.

To define the ASPX page first, note that allowcustompaging is set to False:

<body>


<form id= "dictlist" method= "POST" runat= "Server" >


<table style= "border-collapse:collapse" cellspacing= "0" width= "100%" border= "1" >


<TR>


<td bgcolor= "#c0c000" > Information: <font face= "Arial" color= "#ffffff" > Data Maintenance </FONT>


</td>


</TR>


<tr>


<td><font face= "song Body" ></FONT></td>


</tr>


<tr>


<td><asp:datagrid id= "Mydatagrid" runat= "Server" width= "100%" "pagesize=" allowpaging= "True" autogeneratecolumns= "False" datakeyfield= "Fdictid" >


<selecteditemstyle backcolor= "#FFC080" ></SelectedItemStyle>


<headerstyle backcolor= "#C0C000" ></HeaderStyle>


<Columns>


<asp:buttoncolumn text= "select" headertext= "Choose" commandname= "select" >


<headerstyle font-bold= "True" horizontalalign= "Center" width= "8%" ></HeaderStyle>


<itemstyle font-bold= "True" horizontalalign= "Center" ></ItemStyle>


</asp:ButtonColumn>


<asp:boundcolumn datafield= "Fdictid" sortexpression= "fdictid ASC" headertext= "identification number" >


<headerstyle width= "15%" ></HeaderStyle>


</asp:BoundColumn>


<asp:boundcolumn datafield= "FNAMECN" sortexpression= "FNAMECN ASC" headertext= "name" >


<headerstyle width= "15%" ></HeaderStyle>


</asp:BoundColumn>


<asp:boundcolumn datafield= "Fnameen" sortexpression= "fnameen ASC" headertext= "English name" >


<headerstyle width= "15%" ></HeaderStyle>


</asp:BoundColumn>


<asp:boundcolumn datafield= "Fnote" sortexpression= "fnote ASC" headertext= "describe" >


<headerstyle width= "47%" ></HeaderStyle>


</asp:BoundColumn>


</Columns>


<pagerstyle visible= "False" ></PagerStyle>


</asp:datagrid></td>


</tr>


</TABLE>


<table style= "border-collapse:collapse" cellspacing= "0" width= "100%" bgcolor= "#ff9966" border= "1" >


<TR>


<td align= "right" ><asp:linkbutton id= "Btnfirst" runat= "Server" commandargument= "fist" > Home page </asp: linkbutton>  


<asp:linkbutton id= "Btnprev" runat= "Server" width= "36px" commandargument= "prev" > previous page </asp:linkbutton >  


<asp:linkbutton id= "Btnnext" runat= "Server" commandargument= "Next" > Next </asp:linkbutton>   


<asp:linkbutton id= "btnlast" runat= "Server" commandargument= "last" > End </asp:linkbutton>   


<asp:label id= "Lblcurrentindex" runat= "Server" ></asp:label>/<asp:label id= "LblPageCount" runat= "Server" ></asp:label>  


Jump to <asp:textbox id= "Txtgopage" runat= "Server" width= "30px" cssclass= "TextBox" ></asp:TextBox>


<asp:button id= "Btngo" runat= "server" text= "Go" cssclass= "button" width= "29px" ></asp:button></td >


</TR>


</TABLE>


</form>


codebehind main Function part code:


private void Page_Load (object sender, System.EventArgs e)


{


//Place user code here to initialize page


myconnection = new SqlConnection (system.configuration.configurationsettings.appsettings["ConnString"));


if (! IsPostBack)


Bindgrid ();


}


public void Bindgrid ()


{


string strSQL = "SELECT * from T_dict";


SqlDataAdapter mycommand = new SqlDataAdapter (strSQL, MyConnection);


DataSet ds = new DataSet ();


Mycommand.fill (ds, "t_dict");


Mydatagrid.datasource=ds. tables["T_dict"]. DefaultView;


Mydatagrid.databind ();


Showstatspage ();


}


private void Pagerbuttonclick (object sender, System.EventArgs e)


{


//Get LinkButton parameter value


String arg = ((LinkButton) sender). CommandArgument;


switch (ARG)


{


case ("Next"):


if (Mydatagrid.currentpageindex < (mydatagrid.pagecount-1))


Mydatagrid.currentpageindex + +;


break;


case ("prev"):


if (Mydatagrid.currentpageindex > 0)


Mydatagrid.currentpageindex--;


break;


case ("fist"):


mydatagrid.currentpageindex=0;


break;


case ("last"):


Mydatagrid.currentpageindex = (mydatagrid.pagecount-1);


break;


Default:


/Page Value


Mydatagrid.currentpageindex = Convert.ToInt32 (ARG);


break;


}


Bindgrid ();


}


void Showstatspage ()


{


//Display page information


lblcurrentindex.text = "[<font color=" Blue "> Current:" + ((int) mydatagrid.currentpageindex+1) + "page </font> ]";


lblpagecount.text = "[<font color=" Blue "> Total:" + mydatagrid.pagecount + "page </font>]";


}


private void Mydatagrid_pageindexchanged (object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)


{


//Processing of digital methods


mydatagrid.currentpageindex = E.newpageindex;


Bindgrid ();


}


private void Btngo_click (object sender, System.EventArgs e)


{


//Page Direct jump code


if (TxtGoPage.Text.Trim ()!= "")


{


int Pagei=int32.parse (TxtGoPage.Text.Trim ())-1;


if (pagei >=0 && pagei < (mydatagrid.pagecount))


mydatagrid.currentpageindex = Pagei;


}


Bindgrid ();


}


//----------------------Paging code end

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.