tags:

views:

40

answers:

2

Hi , I have .aspx page . that Have the GridviewChild Within another gridviewParent. My GridviewChild has Columns with some controls.out of which it has Dropdown controls .I want to fill the Data in dropdowns

GridViewParent
           GridViewChild
                     Columns
                        DropDownControl

This is harachy that i want to explian.On which event of which Grid I can do fillDropDown . Please suggest. Also how to get selected value (Which Events)? If possible send me code in c#

A: 

You can use RowDataBound event of the GridViewChild control to fill the drop down lists. To get the selected value of a drop down list u can say something like this:

DropDownList ddl = GridViewParent.GridViewChild.Rows[someRowIndex].Cells[someCellIndex].FindControl("DropDownlist1") as DropDownList;
string v = ddl.SelectedItem.Text;

I hope that was beneficial to u.

SubPortal
A: 

Hey,

Bind the child gridview with parent data:

<ItemTemplate>
   <GridView id="childGrid" .. DataSource='<%# Eval("Items") %>' ItemDataBound="child_itemdatabound">
<ItemTemplate>

And then proceed to bind the DDL in the itemdatabound event:

.. child_itemdatabound(..)
{
   DropDownList ddl = e.Row.FindControl("ddl") as DropDownList;
   if (ddl != null)
   {
      //Load from data source
      ddl.DataSource = dal.GetData();
      ddl.DataBind();

      //You can set the selected value here too; e.Row.DataItem represents the bound data object
   }
}

You can also get the selected value in the same way, as mentioned in the other post.

Brian