I have a RADGrid on a page. The DetailTable/GridTableView has two GridTemplateColumns that each contains a CheckBox object (unbound). The desired behavior is that CheckBox chkRuleEdition is always initially disabled. When CheckBox chkSelect is checked, I enable chkRuleEdition, when I uncheck chkSelect, then is uncheck and disable chkRuleEdition. I have this working fine, except....
When I have a row where chkRuleEdition is enabled and checked, when I expand a different parent row, the chkRuleEdition always reverts back to it's initial enabled/disabled state, in this case, being disabled. I seem to have no ability to change this state in the ItemCreated event of the RADGrid, aside from the initial state when the grid is first loaded. Coping relevant code below (I apologize, but "Format Code Block" is not working for me.)
RadGrid:
<telerik:RadGrid runat="server" ID="rgStudentExtractRequest"
AutoGenerateColumns="false" AllowSorting="false" AllowPaging="false" OnItemCreated="rgStudentExtractRequest_ItemCreated"
Width="780px">
<PagerStyle Mode="NumericPages" />
<MasterTableView DataKeyNames="AcademicYear" AllowMultiColumnSorting="True" HierarchyLoadMode="ServerBind"
GroupLoadMode="Server">
<DetailTables>
<telerik:GridTableView DataKeyNames="AcademicYear" Width="100%" AllowSorting="false" >
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="AcademicYear" MasterKeyField="AcademicYear" />
</ParentTableRelation>
<Columns>
<telerik:GridBoundColumn DataField="Subject" SortExpression="Subject" HeaderText="Subject" Display="true" />
<telerik:GridBoundColumn UniqueName="SubjectCd" DataField="SubjectCd" Display="false" />
<telerik:GridTemplateColumn UniqueName="clmSelect" HeaderText="Full" Display="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate >
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="clmRuleEdition" HeaderText="Rule Edition" Display="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate >
<asp:CheckBox ID="chkRuleEdition" runat="server" Enabled="true" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridBoundColumn DataField="AcademicYear" SortExpression="AcademicYear" HeaderText="" Display="true" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
Script (Event set up in code behind):
function clicked_chkSelect(chkbox, itemId) {
var tableView = $find(itemId.split("__")[0]);
tableView.get_dataItems();
var row = $find(itemId);
var chkFull = chkbox;
var chkRuleEdition = row.findElement("chkRuleEdition");
if (chkFull.checked == false) {
chkRuleEdition.checked =
false;
chkRuleEdition.disabled =
true;
}
else {
chkRuleEdition.disabled =
false;
chkRuleEdition.parentElement.removeAttribute(
"disabled");
}
}
ItemCreated Event (This only seems to set up the Grid on Load, not when the expanded process happens, even though I can trap in Debugger):
Protected Sub rgStudentExtractRequest_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
Try
If e.Item.GetType Is GetType(GridDataItem) Then
Dim item As GridDataItem = CType(e.Item, GridDataItem)
'if this item is from a detail table
If (item.OwnerTableView IsNot rgStudentExtractRequest.MasterTableView) Then
Dim chkSelect As CheckBox = CType(item.FindControl("chkSelect"), CheckBox)
Dim chkRuleEdition As CheckBox = CType(item.FindControl("chkRuleEdition"), CheckBox)
'pass the ClientID of the row itself. We can extract the detail table ID from it
If chkSelect IsNot Nothing Then
chkSelect.Attributes.Add(
"onclick", "clicked_chkSelect(this,'" + item.ClientID + "')")
End If
If chkRuleEdition IsNot Nothing andalso chkSelect isnot Nothing andalso chkSelect.Checked = False Then
chkRuleEdition.Enabled =
False
ElseIf chkRuleEdition IsNot Nothing Then
chkRuleEdition.Enabled =
True
End If
End If
End If
Catch ex As Exception
MessageWindowLogWithError(, ,
Message.Icon.Err, ex, , PageName, System.Reflection.MethodBase.GetCurrentMethod.Name)
End Try
End Sub