Hi,
You can use either
GridView
RowDataBound
event to bind dropdown or you can use a simple
Foreach
loop to iterate and bind each dropdown in a
GridView<br />
. If you use RowDataBound Event, On *.aspx page
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
and on *.aspx.cs use this code below
void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList drdList=(DropDownList)e.Row.FindControl("DropDownList1");
}
}
Or alternatively you can use the code below after DataBinding on GridView1
DropDownList drdList;
foreach (GridViewRow grdRow in GridView1.Rows)
{
drdList = (DropDownList)( GridView1.Rows[ grdRow.RowIndex ].Cells[1].FindControl( "DropDownList1" ));
drdList.DataSource = myDataSet;
drdList.DataValueField = "ColumnName";
drdList.DataTextField = "ColumnName";
drdList.DataBind();
}
You will find more details
here[
^]
Hope this will help.