Question

I have a RadGrid control that is displays disabled or enabled checkboxes based on the database values.

I have a radio button "Select All" that needs to check all enabled checkboxes in the grid. However, I am not able to detect if the checkbox is enabled or disabled.

The html code for the checkbox is:

<telerik:GridTemplateColumn DataField="Certified" HeaderText="Certified" Visible="true">
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" 
        OnCheckedChanged="CheckBox2_CheckedChanged" 
        Enabled='<%# !bool.Parse(Eval("Certified").ToString()) %>' />
    </ItemTemplate>
</telerik:GridTemplateColumn>

My codebehind is:

foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
    if (((CheckBox)dataItem.FindControl("CheckBox2")).Enabled != false) ;
    {
        ((CheckBox)dataItem.FindControl("CheckBox2")).Checked = true;
    }
}

How can I go about returning only enabled checkboxes in the if statement?

Was it helpful?

Solution

You have strange logic, and if statement is ended with comma.

if (((CheckBox)dataItem.FindControl("CheckBox2")).Enabled != false) ;

As the result, they become two separate lines.

{
   ((CheckBox)dataItem.FindControl("CheckBox2")).Checked = true;
}

Solution

foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
    var checkbox = dataItem.FindControl("CheckBox2") as CheckBox;
    if (checkbox.Enabled)
    {
        checkbox.Checked = true;
    }
}

OTHER TIPS

  columns.Bound(c => c.IsSelected)
 .ClientTemplate("<input <#=IsSelected  ? 'checked'  : '' #>  />")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top