views:

81

answers:

1

Hello experts,

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

+1  A: 

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;

}
Dan
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Dim dl As DropDownList = CType(e.Row.FindControl("ddlDecision"), DropDownList) Dim atviolPK As TextBox = CType(e.Row.FindControl("txtViolationPK"), TextBox) dl.SelectedValue = GetDecisionCode(atviolPK.Text) End SubFor some reason both dl and actviolPK are showing as nothing. Please help
acadia