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

Getting values by looping through RADGrid from OnCheckedChanged

2 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 13 Feb 2012, 02:12 PM
I am using RADGrid probably a little differnt than the typical - edit one item, update, save, repeat. I am using the RadGrid mainly because of its ability to maintain state on postback from the server.
I am having trouble looping through the grid from a OnCheckChange function/process.

So I have a Parent / Child Grid setup.  I do have more values assigned, but for simplicity I provided the sample above.  What I am doing is when the check box within the Parent or Child grid is selected I am running a routine - but I am having trouble looping through the vaules.  Below is what I am attempting.  Can someone assist with where I am missing?



Public Sub CheckBoxParent(ByVal sender As System.Object, ByVal e As System.EventArgs)
 
  
For Each item As GridDataItem In rParent.Items  
 
    Dim myCheckbox As CheckBox = DirectCast(item.FindControl("CheckBoxParent"), CheckBox)
 
    Dim hAttributeID As HiddenField = DirectCast(dataItem.FindControl("hAttributeID"), HiddenField)
 
 
  ' Child radGrid
   Dim dg As Telerik.Web.UI.RadGrid = item.FindControl("radChild")
 
        ' trying to Loop through each DataGridItem of the child grid
        For Each dgItem As GridDataItem In dg.Items
     
    Next
 
Next
 
End Sub
 
<telerik:RadGrid id="rParent" runat="server" AllowMultiRowSelection="True">
 <MasterTableView ShowHeader="true" AutoGenerateColumns="false">
<Columns>
<telerik:GridTemplateColumn>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
    <asp:CheckBox id="CheckBoxParent" OnCheckedChanged="findScore"
AutoPostBack="True" runat="server"></asp:CheckBox>
    <%# DataBinder.Eval(Container.DataItem, "KeyID") %>
<asp:HiddenField ID="hAttributeID" runat="Server" Value='<%# DataBinder.Eval(Container.DataItem, "AttributeID") %>' />
 
    <telerik:RadGrid id="rChild" runat="server">
    <MasterTableView ShowHeader="false" AutoGenerateColumns="false">
    <Columns>
    <telerik:GridTemplateColumn>
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "Description") %>
    <%# DataBinder.Eval(Container.DataItem, "AttributeID") %>
 
    <asp:CheckBox id="CheckBoxChild" OnCheckedChanged="findScore"
AutoPostBack="True"  runat="server"></asp:CheckBox>
 
    </ItemTemplate>
   </telerik:GridTemplateColumn>
    </Columns>
    </MasterTableView>
   <ClientSettings EnableRowHoverStyle="false" EnablePostBackOnRowClick="true" />
    </telerik:RadGrid>
 
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>





 

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 13 Feb 2012, 04:24 PM
Any assistance is welcome.  I really hoping to get some guidance on the best use of this..

Basically having a RadGrid with checkboxes.. when someone selects a checkbox - hit the server - run some code based on the columns of the RadGrid - retunr results...

Having problems getting the column data from a OnCheckedChanged Checkbox.
0
Shinu
Top achievements
Rank 2
answered on 14 Feb 2012, 06:55 AM
Hello Rob,

Try the following code.
VB:
Protected Sub findScore(sender As Object, e As EventArgs)
    Dim chk As CheckBox = DirectCast(sender, CheckBox)
    Dim item As GridDataItem = DirectCast(chk.NamingContainer, GridDataItem)
    Dim grid As RadGrid = DirectCast(item.FindControl("rChild"), RadGrid)
    For Each item1 As GridDataItem In grid.MasterTableView.Items
    Next
End Sub

-Shinu.
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or