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

Enabled state of CheckBox in GridTemplateColumn does not persist after expanding Parent group. It always reverts back to what it was on Load

2 Answers 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 15 Jun 2011, 06:40 PM
I have an odd scenerio that is happening:

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

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin
Telerik team
answered on 21 Jun 2011, 01:30 PM
Hi scott,

 The checkbox goes back to its original state because when you expand another row the grid refreshes and all the controls are recreated but the checkbox does not persisted its state because you have changed it only client-side.
One option would be to traverse the hierarchy after the row has been expanded in the Page_PreRender event and there you can set the proper enabled/disabled state of the checkbox. Also another option would be if you use HierarchyLoadMode="Client" this way the grid will not refresh on row expand/collapse and the checkbox will retain its state.

Regards,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Scott
Top achievements
Rank 1
answered on 21 Jun 2011, 04:37 PM
Perfect, Marin! That was just what I was looking for.

Thanks so much!

-Scott
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Marin
Telerik team
Scott
Top achievements
Rank 1
Share this question
or