Page_Load方法如下:
C# 带checkbox和分页的GridView _checkbox    protected void Page_Load(object sender, EventArgs e)
C# 带checkbox和分页的GridView _checkbox    {
C# 带checkbox和分页的GridView _checkbox      if (!IsPostBack)
C# 带checkbox和分页的GridView _checkbox      {
C# 带checkbox和分页的GridView _checkbox        //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox        // CREATE TABLE
C# 带checkbox和分页的GridView _checkbox        //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox        DataTable dt = new DataTable();
C# 带checkbox和分页的GridView _checkbox        dt.Columns.Add("A", System.Type.GetType("System.String"));
C# 带checkbox和分页的GridView _checkbox        dt.Columns.Add("B", System.Type.GetType("System.String"));
C# 带checkbox和分页的GridView _checkbox        dt.Columns.Add("C", System.Type.GetType("System.String"));
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox        //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox        // SET DATA
C# 带checkbox和分页的GridView _checkbox        //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox        for (int i = 0; i < 100; i++)
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          DataRow dr = dt.NewRow();
C# 带checkbox和分页的GridView _checkbox          dr["A"] = "A" + i.ToString();
C# 带checkbox和分页的GridView _checkbox          dr["B"] = "B" + i.ToString();
C# 带checkbox和分页的GridView _checkbox          dr["C"] = "C" + i.ToString();
C# 带checkbox和分页的GridView _checkbox          dt.Rows.Add(dr);
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox        this.GridView1.DataSource = dt.DefaultView;
C# 带checkbox和分页的GridView _checkbox        this.GridView1.DataBind();
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          HtmlInputCheckBox cbox = (HtmlInputCheckBox)GridView1.Rows[i].FindControl("CheckBox1");
C# 带checkbox和分页的GridView _checkbox          cbox.Checked = false;
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox      }
C# 带checkbox和分页的GridView _checkbox    }
 
GridView1_PageIndexChanging方法如下:
C# 带checkbox和分页的GridView _checkbox    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
C# 带checkbox和分页的GridView _checkbox    {
C# 带checkbox和分页的GridView _checkbox      string strHiddenField1 = HiddenField1.Value;
C# 带checkbox和分页的GridView _checkbox      string[] arrHiddenField1 = strHiddenField1.Split(',');
C# 带checkbox和分页的GridView _checkbox      List<string> listAdd = new List<string>();
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox      for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
C# 带checkbox和分页的GridView _checkbox      {
C# 带checkbox和分页的GridView _checkbox        HtmlInputCheckBox cbox = (HtmlInputCheckBox)GridView1.Rows[i].FindControl("CheckBox1");
C# 带checkbox和分页的GridView _checkbox        if (cbox.Checked == false)
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          for (int j = 0; j < arrHiddenField1.Length; j++)
C# 带checkbox和分页的GridView _checkbox          {
C# 带checkbox和分页的GridView _checkbox            if (String.IsNullOrEmpty(arrHiddenField1[j]))
C# 带checkbox和分页的GridView _checkbox            {
C# 带checkbox和分页的GridView _checkbox              continue;
C# 带checkbox和分页的GridView _checkbox            }
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox            if (GridView1.Rows[i].Cells[1].Text.Equals(arrHiddenField1[j]))
C# 带checkbox和分页的GridView _checkbox            {
C# 带checkbox和分页的GridView _checkbox              arrHiddenField1[j] = "";
C# 带checkbox和分页的GridView _checkbox            }
C# 带checkbox和分页的GridView _checkbox          }
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox        else
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          bool bolExist = false;
C# 带checkbox和分页的GridView _checkbox          for (int j = 0; j < arrHiddenField1.Length; j++)
C# 带checkbox和分页的GridView _checkbox          {
C# 带checkbox和分页的GridView _checkbox            if (String.IsNullOrEmpty(arrHiddenField1[j]))
C# 带checkbox和分页的GridView _checkbox            {
C# 带checkbox和分页的GridView _checkbox              continue;
C# 带checkbox和分页的GridView _checkbox            }
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox            if (GridView1.Rows[i].Cells[1].Text.Equals(arrHiddenField1[j]))
C# 带checkbox和分页的GridView _checkbox            {
C# 带checkbox和分页的GridView _checkbox              bolExist = true;
C# 带checkbox和分页的GridView _checkbox              break;
C# 带checkbox和分页的GridView _checkbox            }
C# 带checkbox和分页的GridView _checkbox          }
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox          if (!bolExist)
C# 带checkbox和分页的GridView _checkbox          {
C# 带checkbox和分页的GridView _checkbox            listAdd.Add(GridView1.Rows[i].Cells[1].Text);
C# 带checkbox和分页的GridView _checkbox          }
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox      }
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox      strHiddenField1 = "";
C# 带checkbox和分页的GridView _checkbox      for (int i = 0; i < arrHiddenField1.Length; i++)
C# 带checkbox和分页的GridView _checkbox      {
C# 带checkbox和分页的GridView _checkbox        if (!String.IsNullOrEmpty(arrHiddenField1[i]))
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          strHiddenField1 += arrHiddenField1[i] + ",";
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox      }
C# 带checkbox和分页的GridView _checkbox      for (int i = 0; i < listAdd.Count; i++)
C# 带checkbox和分页的GridView _checkbox      {
C# 带checkbox和分页的GridView _checkbox        if (!String.IsNullOrEmpty(listAdd[i]))
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          strHiddenField1 += listAdd[i] + ",";
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox      }
C# 带checkbox和分页的GridView _checkbox      HiddenField1.Value = strHiddenField1;
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox      //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox      // CREATE TABLE
C# 带checkbox和分页的GridView _checkbox      //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox      DataTable dt = new DataTable();
C# 带checkbox和分页的GridView _checkbox      dt.Columns.Add("A", System.Type.GetType("System.String"));
C# 带checkbox和分页的GridView _checkbox      dt.Columns.Add("B", System.Type.GetType("System.String"));
C# 带checkbox和分页的GridView _checkbox      dt.Columns.Add("C", System.Type.GetType("System.String"));
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox      //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox      // SET DATA
C# 带checkbox和分页的GridView _checkbox      //----------------------------------------------------------
C# 带checkbox和分页的GridView _checkbox      for (int i = 0; i < 100; i++)
C# 带checkbox和分页的GridView _checkbox      {
C# 带checkbox和分页的GridView _checkbox        DataRow dr = dt.NewRow();
C# 带checkbox和分页的GridView _checkbox        dr["A"] = "A" + i.ToString();
C# 带checkbox和分页的GridView _checkbox        dr["B"] = "B" + i.ToString();
C# 带checkbox和分页的GridView _checkbox        dr["C"] = "C" + i.ToString();
C# 带checkbox和分页的GridView _checkbox        dt.Rows.Add(dr);
C# 带checkbox和分页的GridView _checkbox      }
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox      this.GridView1.DataSource = dt.DefaultView;
C# 带checkbox和分页的GridView _checkbox      GridView1.PageIndex = e.NewPageIndex;
C# 带checkbox和分页的GridView _checkbox      GridView1.DataBind();
C# 带checkbox和分页的GridView _checkbox
C# 带checkbox和分页的GridView _checkbox      arrHiddenField1 = strHiddenField1.Split(',');
C# 带checkbox和分页的GridView _checkbox      for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
C# 带checkbox和分页的GridView _checkbox      {
C# 带checkbox和分页的GridView _checkbox        HtmlInputCheckBox cbox = (HtmlInputCheckBox)GridView1.Rows[i].FindControl("CheckBox1");
C# 带checkbox和分页的GridView _checkbox        bool bolCheck = false;
C# 带checkbox和分页的GridView _checkbox        for (int j = 0; j < arrHiddenField1.Length; j++)
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          if (arrHiddenField1[j].Equals(GridView1.Rows[i].Cells[1].Text))
C# 带checkbox和分页的GridView _checkbox          {
C# 带checkbox和分页的GridView _checkbox            bolCheck = true;
C# 带checkbox和分页的GridView _checkbox            break;
C# 带checkbox和分页的GridView _checkbox          }
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox        if (bolCheck)
C# 带checkbox和分页的GridView _checkbox        {
C# 带checkbox和分页的GridView _checkbox          cbox.Checked = true;
C# 带checkbox和分页的GridView _checkbox        }
C# 带checkbox和分页的GridView _checkbox      }
C# 带checkbox和分页的GridView _checkbox    }
 
前台如下:
C# 带checkbox和分页的GridView _checkbox<body>
C# 带checkbox和分页的GridView _checkbox  <form id="form1" runat="server">
C# 带checkbox和分页的GridView _checkbox  <asp:HiddenField ID="HiddenField1" runat="server" />
C# 带checkbox和分页的GridView _checkbox  <div>
C# 带checkbox和分页的GridView _checkbox    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
C# 带checkbox和分页的GridView _checkbox      OnPageIndexChanging="GridView1_PageIndexChanging">
C# 带checkbox和分页的GridView _checkbox      <Columns>
C# 带checkbox和分页的GridView _checkbox        <asp:TemplateField>
C# 带checkbox和分页的GridView _checkbox          <ItemTemplate>
C# 带checkbox和分页的GridView _checkbox            <input id="CheckBox1" type="checkbox" runat="server" />
C# 带checkbox和分页的GridView _checkbox          </ItemTemplate>
C# 带checkbox和分页的GridView _checkbox        </asp:TemplateField>
C# 带checkbox和分页的GridView _checkbox        <asp:BoundField DataField="A" HeaderText="A" />
C# 带checkbox和分页的GridView _checkbox        <asp:BoundField DataField="B" HeaderText="B" />
C# 带checkbox和分页的GridView _checkbox        <asp:BoundField DataField="C" HeaderText="C" />
C# 带checkbox和分页的GridView _checkbox      </Columns>
C# 带checkbox和分页的GridView _checkbox    </asp:GridView>
C# 带checkbox和分页的GridView _checkbox  </div>
C# 带checkbox和分页的GridView _checkbox  </form>
C# 带checkbox和分页的GridView _checkbox</body>