You are unable to bind the selected value of your dropdownlist to your GridViews datasource BECAUSE your dropdownlist has its OWN datasource which it is bound do.
The solution I came up with was to have a hidden textbox in the cell along with the dropdownlist. This is simply a asp:TextBox with the visible property marked as false. The hidden textbox is bound to the appropriate field in the GridView's datasource. The DropDownList is bound to its own DataSource. Good so far? Here is the SOURCE code for my two controls..
< asp:TextBox ID="UBER_USER_CONTROL_IDTextBox" runat="server"
Text='<%# Bind("UBER_USER_CONTROL_ID", "{0}") %>'
Visible="False" Width="60px">< /asp:TextBox>
< asp:DropDownList ID="ddlEditUserControlNames"
runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="sdsUserControlNames"
DataTextField="USER_CONTROL_NAME" DataValueField="UBER_USER_CONTROL_ID" OnDataBound="ddlEditUserControlNames_DataBound"
OnSelectedIndexChanged="ddlEditUserControlNames_SelectedIndexChanged">
< asp:ListItem Selected="True" Value="0">Select An Uber Control< /asp:ListItem>
< /asp:DropDownList>
When a user selects a value in the DropDownList, a method is called OnSelectedIndexChanged="ddlEditUserControlNames_SelectedIndexChanged">
This method sets the value of the hidden textbox for me. Here is the code I use to access the controls within my gridview (or formview in this case):
// ddl edit events
protected void ddlEditApplicationNames_SelectedIndexChanged(object sender, EventArgs e)
{
// APPLICATION_IDTextBox
TextBox txtAppId = (TextBox)fvEditUberApps.FindControl("APPLICATION_IDTextBox");
DropDownList ddl = (DropDownList)sender;
txtAppId.Text = ddl.SelectedValue;
}
The other trick to this, is ensuring the initially selected value of the dropdownlist matches the value in the hidden textbox... I do that by using the event which populated my dropdownlist to begin with... this way:
protected void ddlEditApplicationNames_DataBound(object sender, EventArgs e)
{