Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If its a gridview or any repeater control try this </p> <p>Gridview HTML</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="5" Width="324px" DataKeyNames="CategoryID" OnPageIndexChanging="GridView1_PageIndexChanging"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="CategoryID" HeaderText="CategoryID" /&gt; &lt;asp:BoundField DataField="CategoryName" HeaderText="CategoryName" /&gt; &lt;asp:TemplateField HeaderText="Select"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="CheckBox1" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>CS Codes</p> <pre><code>protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { RememberOldValues(); GridView1.PageIndex = e.NewPageIndex; BindData(); RePopulateValues(); } </code></pre> <p>And</p> <pre><code>private void RememberOldValues() { ArrayList categoryIDList = new ArrayList(); int index = -1; foreach (GridViewRow row in GridView1.Rows) { index = (int) GridView1.DataKeys[row.RowIndex].Value; bool result = ((CheckBox)row.FindControl("CheckBox1")).Checked; // Check in the Session if (Session[CHECKED_ITEMS] != null) categoryIDList = (ArrayList)Session[CHECKED_ITEMS]; if (result) { if (!categoryIDList.Contains(index)) categoryIDList.Add(index); } else categoryIDList.Remove(index); } if (categoryIDList != null &amp;&amp; categoryIDList.Count &gt; 0) Session[CHECKED_ITEMS] = categoryIDList; } </code></pre> <p>And</p> <pre><code>private void RePopulateValues() { ArrayList categoryIDList = (ArrayList)Session[CHECKED_ITEMS]; if (categoryIDList != null &amp;&amp; categoryIDList.Count &gt; 0) { foreach (GridViewRow row in GridView1.Rows) { int index = (int)GridView1.DataKeys[row.RowIndex].Value; if (categoryIDList.Contains(index)) { CheckBox myCheckBox = (CheckBox) row.FindControl("CheckBox1"); myCheckBox.Checked = true; } } } } </code></pre> <p>Bind Data Code</p> <p><strong>EDIT</strong></p> <pre><code>/* QUERY */ private const string QUERY_SELECT_ALL_CATEGORIES = "SELECT * FROM Categories"; private void BindData() { SqlConnection myConnection = new SqlConnection(ConnectionString); SqlDataAdapter ad = new SqlDataAdapter(QUERY_SELECT_ALL_CATEGORIES, myConnection); DataSet ds = new DataSet(); ad.Fill(ds, "Categories"); GridView1.DataSource = ds; GridView1.DataBind(); } </code></pre> <p>For more details chk this <a href="http://aspalliance.com/774_Maintaining_State_of_CheckBoxes_While_Paging_in_a_GridView_Control.all" rel="nofollow">Maintaining_State_of_CheckBoxes</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload