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

checked status fails..

1 Answer 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 14 Feb 2012, 02:22 PM
Hi Telerik,

I have made a custom checkbox where i can bind the id(DatabaseID) from the database. I'm using this custom checkbox and other labels in a Radgrid where i dynamically bind the data from the database using a Webservice. Then i have a button who saves the values(in that row to the database) where checkbox is checked. The button need to do a server side postback to the database in order to save the values but onCheckedChanged is server side?  
<telerik:GridTemplateColumn HeaderText="Godkänn" ItemStyle-Width="50px" UniqueName="cChkbox">
     <ItemTemplate>
          <fw:CustomCheckBox DatabaseID='<%# Eval("ID") %>' runat="server" OnCheckedChanged="onCheckedChanged" />
       </ItemTemplate>
</telerik:GridTemplateColumn>


protected void btnAcceptHours_Click(object sender, EventArgs e)
        {
            List<string> AcceptHours = new List<string>();
            foreach (GridDataItem item in rgAvvaktandeTim.Items)
            {
                foreach (Control c in item.Controls)
                {
                    foreach (Control d in c.Controls)
                    {
                        if (d is CustomControls.CustomCheckBox)
                        {
                            if ((d as CustomControls.CustomCheckBox).Checked == true)
                            {
                                AcceptHours.Add((d as CustomControls.CustomCheckBox).DatabaseID);
                                goto ContinueOuterIteration;
                            }
                        }
                    }
                }
            ContinueOuterIteration:
                continue;
            }
The problem is that where in code behind(button) the checked status is always false. But i have tested this in the custom checkbox class that the checked status is changed so there is a loss somewhere..

Help please!

Thanks!
Andreas E



1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 16 Feb 2012, 09:08 PM
Andreas:

Since your check boxes are embedded within the RadGrid, you'll need to use the .FindControl method to gain access to them and to read the state of the property settings.

Here's some similar code to assist:
if (e.Item is GridDataItem)
{
    GridDataItem item = e.Item as GridDataItem;
    CheckBox box = (CheckBox)item.FindControl("cbChecked");
 
   .....
}

I would also suggest that you take a look at the Persisting CheckBox control state in GridTemplateColumn on rebind documentation page for insights here. Be sure to click the C# tab to see the server-side code required.

Hope this helps!
Tags
Grid
Asked by
Andreas
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or