This is a migrated thread and some comments may be shown as answers.

[Solved] Obtaining the state of the Checkbox

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 2
Chris asked on 10 Aug 2009, 08:30 PM
OK, I've been searching for an answer for quite a while now and still, nothing works.  I've tried both CheckboxColumn and Template column.  In both cases, I can check the box on the form, but when I do a postback, the state is always reported as the default in which I set it.

I'm not doing anything fancy here.  All I want is to be able to loop through the records and see if the user checked anything and set up the operation I need to do on that. 

Here is the current code:

ASPX:

               <radG:GridTemplateColumn UniqueName="cbCol"
                                        HeaderText="Select">
                  <ItemTemplate>  
                     <asp:CheckBox ID="cbSelection" runat="server" Checked="false" />  
                  </ItemTemplate>  
               </radG:GridTemplateColumn>                 


ASPX.CS

   protected void ExecuteSubmit(object sender, EventArgs e)
   {
      foreach (GridDataItem X in RadGrid1.Items)
      {
         CheckBox ItemSelect = (CheckBox)X["cbCol"].FindControl("cbSelection");

         if (ItemSelect.Checked)
         {
                 //  NEVER reaches here if checkbox was defaulted to 'unchecked' regardless of the state of the control on postback.
         }
      }
   }

What am I missing?



1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Aug 2009, 05:09 AM
Hello Chris,

The checkbox control state is not persisted on postbacks so you need to persist the checked state on CheckChanged event of the checkbox and then loop through the rows in the grid. You may find the following help document article useful to achieve the same scenario.
Persisting CheckBox control state in GridTemplateColumn on rebind

Thanks
Princy.
Tags
Grid
Asked by
Chris
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or