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

[Solved] DropDownList populated based on value in parent grid

1 Answer 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 11 Jun 2009, 10:06 AM

This is the situation.

I have a grid with a two level hierachy. In the child grid I have a dropdowncolumn defined. The values for the dropdown come from a business object that returns a List<IServer>. The GetServerList method of the BLL takes a parameter (int environmentID) to ensure only the servers for a particular environment are returned. The environmentID is held on the parent table and can I assume be accessed using the following notation.

 

e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][

"EnvironmentID"]

my problem is that I cannot for the life of me work out how to populate the drop down. If it didnt require any parameters then I would simply set it to an objectdatasource defined on the page (as I have for other dropdown columns.)

This must be possible, I have tried stuff in the ItemDataBound/ItemCreated events but just cant seem to get it working.

Someone must have done this before. Any help would be much appreciated.

Regards

Ben Blackmore.

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Jun 2009, 10:49 AM
Hello Ben,

I hope you are trying to access the datakeyvalue of the parent row so as to populate the dropdownlist. If so, you can try out the following code:
c#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name=="Detail"
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item;             
            GridDataItem parentrow = (GridDataItem)editItem.OwnerTableView.ParentItem; 
            string strtxt = parentrow.GetDataKeyValue("EnvironmentID").ToString(); //to get the datakeyvalue of the parent table 
            DropDownList ddl = (DropDownList)editItem["DropDownColumnUniqueName"].Controls[0]; 
        } 
    } 

Hope this helps...
Princy.
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or