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

NestedViewTemplate parent item value

2 Answers 319 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 25 Sep 2013, 08:56 PM
I have a grid with a nested view template. Inside the nested view I have a checkbox. When the value changes, I need to check a value in the parent item's data. How do I get this value?

Using the code below I can get the parent Item, but its DataItem is null.
GridNestedViewItem nesteditem = (GridNestedViewItem)button.NamingContainer;
GridDataItem item = nesteditem.ParentItem;

What am I missing?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Sep 2013, 08:59 AM
Hi Rayne,

I guess you want to change some value of the parent item when a control of checkbox is checked inside the NestedViewTemplate.Please try the below code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemCreated="RadGrid1_ItemCreated">  
    <MasterTableView DataKeyNames="CustomerID">
        <Columns>       
            <telerik:GridBoundColumn DataField="ContactTitle" HeaderText="Contact title"  UniqueName="ContactTitle">
            </telerik:GridBoundColumn>   
        </Columns>
        <NestedViewSettings >
            <ParentTableRelation>
                <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
            </ParentTableRelation>
        </NestedViewSettings>
        <NestedViewTemplate>
            <asp:Panel ID="Panel1" runat="server">
                <table>
                    <tr>
                        <td>
                            <asp:CheckBox ID="CheckBox1" runat="server" />
                        </td>
                    </tr>                 
                </table>
            </asp:Panel>
        </NestedViewTemplate>
    </MasterTableView>   
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridNestedViewItem)
       {        
           CheckBox check = e.Item.FindControl("CheckBox1") as CheckBox;
           check.AutoPostBack = true;
           check.CheckedChanged += new System.EventHandler(check_CheckedChanged);
       }
   }
 
void check_CheckedChanged(object sender, System.EventArgs e)
   {
       CheckBox checkinner = (CheckBox)sender;
       GridNestedViewItem item = (GridNestedViewItem)checkinner.NamingContainer;
       if (checkinner.Checked)
       {          
              string val = item.ParentItem.GetDataKeyValue("CustomerID").ToString(); //Access the DataKeyValue
              item.ParentItem["ContactTitle"].Text="Some Text";   //Access a bound column      
       }
   }

Thanks,
Princy
0
Rayne
Top achievements
Rank 1
answered on 26 Sep 2013, 12:55 PM
Thanks. this bit of code is what I needed:

item.ParentItem["ContactTitle"].Text="Some Text"; //Access a bound column      
Tags
Grid
Asked by
Rayne
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rayne
Top achievements
Rank 1
Share this question
or