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

reference to parent grid

2 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 02 Dec 2012, 09:57 PM
Hi,
I have a grid in an editform of another grid. The datasource of the second grid is dependant on a datakeyvalue of the first grid. How do i do this in the NeedDataSource event of the second grid?
If I try and use the SelectedIndex I get nothing as first gris is in edit mode.
I am looking for something like below but unfortunately the row is not selected, just inedit mode:
Protected Sub UserNeedDatasource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
Dim DataKey As String = Me.Grid1.MasterTableView.DataKeyValues(Me.Grid1SelectedIndexes(0))("DataKeyName").ToString
Me.Grid2.DataSource = MyDataSource.GetData(DataKey)
end Sub

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Dec 2012, 04:22 AM
Hi,

You can access the datakeynames in ItemDataBound event as shown below.
C#:
protected void RadGrid2_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;
        string value = item.GetDataKeyValue("ID").ToString();
        //populate the inner grid here
    }
}

Thanks,
Shinu
0
Roger
Top achievements
Rank 1
answered on 06 Dec 2012, 11:11 PM
Hi Shinu,
thanks for the reply...I was hoping to get a reference from the NeedDataSource event of Grid2 but this isn't so.
Since I need the datakeyvalue for editing/deleting/inserting I saved it as a session variable in the ItemDataBound event of Grid1. This works fine.
Tags
Grid
Asked by
Roger
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Roger
Top achievements
Rank 1
Share this question
or