Reputation: 2982
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?
Upvotes: 1
Views: 2907
Reputation: 2129
columns.Bound(c => c.IsSelected)
.ClientTemplate("<input <#=IsSelected ? 'checked' : '' #> />")
Upvotes: 0
Reputation: 62260
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;
}
foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
var checkbox = dataItem.FindControl("CheckBox2") as CheckBox;
if (checkbox.Enabled)
{
checkbox.Checked = true;
}
}
Upvotes: 2