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

accessing the datakey of parent for a grid inside nestedviewtemplate

3 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 06 Feb 2009, 08:31 PM
Hi,
this is in respect with this forum thread I started:
http://www.telerik.com/community/forums/aspnet-ajax/grid/displaying-another-grid-inside-radgrid.aspx#737663

I have a grid and two buttons inside the nestedviewtemplate of a grid.
on click of the button I want to bind the grid to a datasource based on the datakeyvalue for that row.

I am unable to determine the datakeyvalue for the row in which I click the button.

My ItemIndex is always -1

Can you help?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Feb 2009, 07:51 AM
Hi,

You can access sthe parent item of the nested view template by using the code below:

cs:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
{  
if (e.CommandName == "Show/Hide")  
    {  
        GridNestedViewItem item = (GridNestedViewItem)e.Item; 
//ID is the DataKeyValue of the MasterTable 
        string customerid = item.ParentItem.GetDataKeyValue("ID").ToString(); 
    } 


Thanks,
Princy
0
newbie
Top achievements
Rank 1
answered on 09 Feb 2009, 06:17 PM
Hi Princy.

That doesn't seem to be working for me.
It gives me an error
'Telerik.Web.UI.GridNestedViewItem' does not contain a definition for 'ParentItem' and no extension method 'ParentItem' accepting a first argument of type 'Telerik.Web.UI.GridNestedViewItem' could be found (are you missing a using directive or an assembly reference?)'

Please suggest.
0
Princy
Top achievements
Rank 2
answered on 10 Feb 2009, 05:28 AM
Hi,

Which version of RadGrid are you using? I tried the following code with the latest version( 2008.3.1314.20).The ParentItem property is not defined with older versions of RadGrid and is added with versions starting from 2008.3.1125 . So you can either try upgrading your RadGrid control to the latest version or check out a workaround solution given below:
cs:
 protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        if (e.CommandName == "Show/Hide") 
        { 
            GridNestedViewItem nestedItem = (GridNestedViewItem)e.Item; 
            foreach (GridDataItem item in nestedItem.OwnerTableView.Items) 
            { 
                if (item.Expanded) 
                { 
                    string customerid = item.GetDataKeyValue("ID").ToString(); 
                } 
            } 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
newbie
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
newbie
Top achievements
Rank 1
Share this question
or