asp.net|datagrid| Paging
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= "Arial" > </FONT> </td>
</tr>
<tr>
<td> <asp:datagrid id= "Mydatagrid" runat= "Server" width= "100%" pagesize= "allowpaging=" True "autogeneratecolumns=" False "datakeyfield=" "Fdictid" >
<selecteditemstyle backcolor= "#FFC080" > </SelectedItemStyle>
<Columns>
<asp:buttoncolumn text= "Select" headertext= "Choose" commandname= "select"
<itemstyle font-bold= "True" horizontalalign= "Center" > </ItemStyle>
</asp:ButtonColumn>
<asp:boundcolumn datafield= "Fdictid" sortexpression= "fdictid ASC" headertext= "identification number"
</asp:BoundColumn>
<asp:boundcolumn datafield= "FNAMECN" sortexpression= "FNAMECN ASC" headertext= "name" >
</asp:BoundColumn>
<asp:boundcolumn datafield= "Fnameen" sortexpression= "fnameen ASC" headertext= "English name"
</asp:BoundColumn>
<asp:boundcolumn datafield= "Fnote" sortexpression= "fnote ASC" headertext= "describe"
</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 </asp:linkbutton>
<asp:linkbutton id= "Btnprev" runat= "Server" width= "36px" commandargument= "prev" > prev </asp:linkbutton>
<asp:linkbutton id= "Btnnext" runat= "Server" commandargument= "Next" next page </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 the 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
Value of this page
Mydatagrid.currentpageindex = Convert.ToInt32 (ARG);
Break
}
Bindgrid ();
}
void Showstatspage ()
{
Display page Information
Lblcurrentindex.text = "[]";
Lblpagecount.text = "[ total:" + mydatagrid.pagecount + "page ]";
}
private void Mydatagrid_pageindexchanged (object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
How to handle numbers
Mydatagrid.currentpageindex = E.newpageindex;
Bindgrid ();
}
private void Btngo_click (object sender, System.EventArgs e)
{
The code for the page to jump directly
if (TxtGoPage.Text.Trim ()!= "")
{
int Pagei=int32.parse (TxtGoPage.Text.Trim ())-1;
if (Pagei >=0 && pagei (mydatagrid.pagecount))
Mydatagrid.currentpageindex = Pagei;
}
Bindgrid ();
}
----------------------the page-flipping code ends