Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi ,


I have a GridView Inside DataGrid.
In my Gridview I'm using DropDownList.

Now, my question is how to fetch Data from DataSet to DropDownList
Please help me to solve this....


Thanx in advance.....
Posted
Updated 26-Sep-12 1:57am
v4

In this is example I hv used repeater. Same can be achieved using gridview.

C#
protected void rptr_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DropDownList ddl = null;
        
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            ddl = (DropDownList)e.Item.FindControl("YourDropDownListID");
            
            DataRowView drv = (DataRowView)e.Item.DataItem;

            BindDropDown(ddl, drv["YourDropDownValueFromDataBase"].ToString());
        }
    }


Use BindDropDown(DropDownList ddl, string selectedValue) to bind your dropdown and set selected value using second parameter.
 
Share this answer
 
Hello,

you can use OnRowDataBound event of grid view to assign data set to drop down list.

Before assignment get control using findControl method and then assign appropriate values to drop down list.

Please let us know if any.
 
Share this answer
 
v3
Comments
[no name] 26-Sep-12 8:19am    
protected void gdDrawing_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
GridView GV = (GridView)e.Item.FindControl("GV");

DataSet ds = objDesign.Get_Drawing_Element_Details("2", "1");

GV.DataSource = ds;

GV.DataBind();
}
}
This is the Code i wrote without DropDown ,
but i dont no how to assign datatext & value field to inside a grid please help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900