Setting selectedvalue for a dropdownlist in GridView

asp.netgridview

I have a dropdownlist in my Gridview and I am binding a datasource to the gridview.

Though all the records are displaying properly the dropdown value is not selected.

How do I set something like

<%# Bind("Country") %> for a dropdownlist in the Gridview in ASP.net.

Thanks

Best Answer

You can hook into the RowDataBound event for the grid view, find the control and set the value.

protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{

     var dropdownList = e.Row.FindControl("YOUR_DROP_DOWN") as DropDownList;
     dropdownList .SelectedIndex = SET_VALUE_HERE;

}