The GridView's own paging functionality is implemented with:
To implement the Grdview paging functionality
The operation is as follows:
1, change the AllowPaging property of the Grdview control to True.
2. Change the PageSize property of the Grdview control to any value (default is 10)
3, change the Grdview control Pagesetting->mode to numeric, etc. (default is numeric) This property is a paging style.
The GridView property is set up so that you can see the paging style from the page as well.
Now it's time to implement the paging feature:
1, after <<asp:gridview id=......> Add, onpageindexchanging= "gridview1_pageindexchanging"
2, in the corresponding aspx.cs add:
protected void Gridview1_pageindexchanging (object sender, Gridviewpageeventargs e)
{
Gridview1.pageindex = E.newpageindex;
Initpage (); Functions that rebind the GridView data
}
3,
Gridview1.pageindex = E.newpageindex;
And then rebind the GridView.
GridView Add checkbox column to implement all/all cancellation features
First the GridView edits the template, adds the checkbox control to the templates, and then converts the newly added column field to templatefiled
Background code:
Copy Code code as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
public partial class Default5:System.Web.UI.Page
{
SqlConnection Sqlcon;
String Strcon = "Data source= (local);D atabase= North Wind trade; Uid=sa; Pwd=sa ";
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Bind ();
}
}
protected void Checkbox2_checkedchanged (object sender, EventArgs e)
{
for (int i = 0; I <= gridview1.rows.count-1; i++)
{
CheckBox Cbox = (checkbox) Gridview1.rows[i]. FindControl ("CheckBox1");
if (checkbox2.checked = = True)
{
Cbox. Checked = true;
}
Else
{
Cbox. Checked = false;
}
}
}
protected void button2_click (object sender, EventArgs e)
{
Sqlcon = new SqlConnection (Strcon);
SqlCommand sqlcom;
for (int i = 0; I <= gridview1.rows.count-1; i++)
{
CheckBox Cbox = (checkbox) Gridview1.rows[i]. FindControl ("CheckBox1");
if (Cbox. Checked = = True)
{
String sqlstr = "Delete from flying Fox Studio where ID number = '" + gridview1.datakeys[i]. Value + "'";
sqlcom = new SqlCommand (sqlstr, Sqlcon);
Sqlcon. Open ();
Sqlcom. ExecuteNonQuery ();
Sqlcon. Close ();
}
}
Bind ();
}
protected void Button1_Click (object sender, EventArgs e)
{
checkbox2.checked = false;
for (int i = 0; I <= gridview1.rows.count-1; i++)
{
CheckBox Cbox = (checkbox) Gridview1.rows[i]. FindControl ("CheckBox1");
Cbox. Checked = false;
}
}
public void bind ()
{
String sqlstr = "SELECT Top 5 * from flying Fox Studio";
Sqlcon = new SqlConnection (Strcon);
SqlDataAdapter Myda = new SqlDataAdapter (Sqlstr, Sqlcon);
DataSet myds = new DataSet ();
Sqlcon. Open ();
Myda. Fill (myDS, "Tb_member");
Gridview1.datasource = myds;
Gridview1.datakeynames = new string[] {"Identity card number"};
Gridview1.databind ();
Sqlcon. Close ();
}
}
Foreground main code:
Copy Code code as follows:
<asp:gridview id= "GridView1" runat= "Server" allowsorting= "True" autogeneratecolumns= "False"
cellpadding= "3" font-size= "9pt" backcolor= "white" bordercolor= "#CCCCCC" borderstyle= "None" borderwidth= "1px" >
<footerstyle backcolor= "White" forecolor= "#000066"/>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:checkbox id= "CheckBox1" runat= "Server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield= "ID number" headertext= "User ID" sortexpression= "identity card number"/>
<asp:boundfield datafield= "name" headertext= "User name" sortexpression= "name"/>
<asp:boundfield datafield= "Home Address" headertext= "Home Address" sortexpression= "Home Address"/>
</Columns>
<rowstyle forecolor= "#000066"/>
<selectedrowstyle backcolor= "#669999" font-bold= "True" forecolor= "white"/>
<pagerstyle backcolor= "White" forecolor= "the #000066" horizontalalign= "left"/>
</asp:GridView>
<asp:checkbox id= "CheckBox2" runat= "Server" autopostback= "True" font-size= "9pt" oncheckedchanged= "checkbox2_" CheckedChanged "
text= "Select All"/>
<asp:button id= "Button1" runat= "Server" font-size= "9pt" text= "Cancel" onclick= "Button1_Click"/>
<asp:button id= "Button2" runat= "Server" font-size= "9pt" text= "delete" onclick= "button2_click"/>