views:

96

answers:

1

Hi All

I have a GridView control that has one column of checkboxes set up like this:

<asp:TemplateField>
   <ItemTemplate>
        <asp:CheckBox ID="RowCheckBox" runat="server" Enabled="false" Checked='<%# (bool)DataBinder.Eval(Container.DataItem ,"Associated") %>'/>
   </ItemTemplate>
</asp:TemplateField>

Then when the user clicks an Edit button I run a script that enables all the checkboxes (which works fine), and then when the user then clicks on a checkbox the tick is appearing or disappearing as it should.

The problem I'm having is that when I try to read the value of the checkbox from the codebehind:

CheckBox checkBox = (CheckBox) row.FindControl("RowCheckBox");
bool checked = checkBox.Checked;

If the value bound to it was true then checked is still true, no matter if it was toggled or not.

Has anyone got any ideas why this is?

Thanks

Clivest

Edit: Corrected a spelling mistake. Question still stands though...

A: 

In the end I couldn't find a solution so have done a work around:

  1. Add a Hidden Field to the Template Field,
  2. Update the value of the hidden field to True or False with Javascript (adding an onclick attribute to the checkbox),
  3. In the code behind cast the hidden field value to a bool and use that instead of the checked property of the checkbox.

I think it might be something to do with View States, but I'm not sure what they are and haven't got the time to investigate unfortunately.

Clivest

Clivest