c# - Maintain state of checkboxlist inside gridview asp.net -


i have checkboxlist(with 4 listitems) in 1 of columns of gridview.it not populated database.i want maintain state of listitems(checked or unchecked) when navigate page of gridview.i have tried setting enableviewstate="true" gridview , checkboxlist doesnt work. here's html mark-up:

<asp:gridview id="grdunits" runat="server" autogeneratecolumns="false"                         allowpaging="true" pagesize="20" onrowdatabound="grdunit_rowdatabound" onpageindexchanging="grdunit_pageindexchanging"                          rowstyle-backcolor="white" alternatingrowstyle-backcolor="lightblue"  borderstyle="solid"                         height="426px" width="1500px">                         <pagersettings  mode="numeric" />                         <columns>                              <asp:boundfield datafield="sukey" headertext="unit code" />                              <asp:boundfield datafield="credits" headertext="credits"/>                               <asp:templatefield>                                  <headertemplate>standard semester or term</headertemplate>                                  <itemtemplate>                                      <asp:checkboxlist id="cblstandardsem" runat="server" repeatdirection="horizontal" textalign="left" repeatlayout="table">                                          <asp:listitem value="summertermsemst" text="14st"></asp:listitem>                                          <asp:listitem value="semester1st" text="14s1"></asp:listitem>                                          <asp:listitem value="wintertermsemst" text="14wt"></asp:listitem>                                          <asp:listitem value="semester2st" text="14s2"></asp:listitem>                                      </asp:checkboxlist>                                  </itemtemplate>                                  <itemstyle width="300px" horizontalalign="center" verticalalign="middle"/>                              </asp:templatefield>                          </columns>                     </asp:gridview> 

the code behind:

protected void page_load(object sender, eventargs e) {     if (!this.ispostback)     {           binddatagrid();     } }  private void binddatagrid() {     //fetch data database     grdunits.databind(); }  protected void grdunit_pageindexchanging(object sender, gridviewpageeventargs e) {      grdunits.pageindex = e.newpageindex;      binddatagrid(); } 

i have come across posts mention maintaining state checkboxlist outside gridvew isnt helpful. unable figure out way maintaining state of checkboxlist(which inside gridview) , saving database.

it doesn't matter whether set enableviewstate="true" or not, when control (checkboxlist) not populating or not checking database control lose checked data @ time call grid-view databind method.

the way think of keep control data in session variable going insane if have hundreds of records in grid-view. , don't wanna make server slow definitely.

so recommend handle state via database if have large number of records on grid-view.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -