asp.net GridView控件中诗选全选和全不选功能

时间:2022-12-19 04:03:32
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration; public partial class _Default : System.Web.UI.Page
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(constr);
conn.Open();
string sql = "select * from student";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
for (int i = ; i <= GridView1.Rows.Count - ; i++)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkCheck");
if (chkAll.Checked == true)
{
chk.Checked = true;
}
else
{
chk.Checked = false;
}
}
}
}
<asp:TemplateField>
                    <ItemTemplate>
<asp:CheckBox ID="chkCheck" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<configuration>
<connectionStrings >
<add name="constr" connectionString="server=.\sqlexpress;database=db2016;uid=sa;pwd=123;"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web> </configuration>

asp.net GridView控件中诗选全选和全不选功能

asp.net GridView控件中诗选全选和全不选功能