Need to update data from dropdown list in DetailsView

I have a DetailsView with a dropdown list. When I select a value from the ddl, the value I selected won't update to the stored procedure. The sproc works fine and I can update other fields. It's just the ddl that won't send the selected value to the sproc.

The below snippet shows the abbreviated code. Thanks.
<asp:DetailsView ID="dvStores" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodYellow"
	BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataSourceID="GetStoreDetail" ForeColor="Black"
	GridLines="None" Height="50px" CssClass="normal" Width="210px">
<asp:TemplateField HeaderText="State" SortExpression="StateLong">
				<asp:DropDownList ID="ddlState" runat="server" DataSourceID="GetStateListShort" DataTextField="StateLong"
					DataValueField="StateId" SelectedValue='<%# Eval("StateID") %>'>
				<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("StateLong") %>'></asp:TextBox>
				<asp:Label ID="Label1" runat="server" Text='<%# Bind("StateLong") %>'></asp:Label>
<asp:SqlDataSource ID="GetStoreDetail" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
	SelectCommand="KScoop_GetStoreDetail" SelectCommandType="StoredProcedure" UpdateCommand="KScoop_UpdateStore" UpdateCommandType="StoredProcedure">
		<asp:ControlParameter ControlID="grdStores" DefaultValue="-1" Name="StoreId" PropertyName="SelectedValue"
			Type="Int16" Size="1" />
		<asp:ControlParameter  ControlID="grdStores"  Name="StateId" PropertyName="SelectedValue"   Type="Int16" />

Open in new window

Who is Participating?
Oliver AmayaConnect With a Mentor EntrepeneurCommented:
How about if you add the following code in your page_load event (I'm assuming you're using c#):
GetStoreDetail.UpdateParameters["StateId"].ControlID = ((DropDownList)dvStores.FindControl("ddlState")).ClientID;

Open in new window

Oliver AmayaEntrepeneurCommented:
Hi, shouldn't the Name property point to ddlStates?
  <asp:ControlParameter  ControlID="ddlStates"  Name="StateId" PropertyName="SelectedValue"   Type="Int16" />

Open in new window

barnescoAuthor Commented:
That's what I thought, too. But when I did, I received an error: Cannot insert a NULL value.
barnescoAuthor Commented:
I found the answer: I need to insert the DataKeyNames="StoreID" in the DetailsView.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.