Link to home
Start Free TrialLog in
Avatar of barnesco
barnesco

asked on

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">
			<EditItemTemplate>
				<asp:DropDownList ID="ddlState" runat="server" DataSourceID="GetStateListShort" DataTextField="StateLong"
					DataValueField="StateId" SelectedValue='<%# Eval("StateID") %>'>
				</asp:DropDownList>
			</EditItemTemplate>
			<InsertItemTemplate>
				<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("StateLong") %>'></asp:TextBox>
			</InsertItemTemplate>
			<ItemTemplate>
				<asp:Label ID="Label1" runat="server" Text='<%# Bind("StateLong") %>'></asp:Label>
			</ItemTemplate>
		</asp:TemplateField>
 
</asp:DetailsView>
 
 
 
 
<asp:SqlDataSource ID="GetStoreDetail" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
	SelectCommand="KScoop_GetStoreDetail" SelectCommandType="StoredProcedure" UpdateCommand="KScoop_UpdateStore" UpdateCommandType="StoredProcedure">
	<SelectParameters>
		<asp:ControlParameter ControlID="grdStores" DefaultValue="-1" Name="StoreId" PropertyName="SelectedValue"
			Type="Int16" Size="1" />
	</SelectParameters>
	
	<UpdateParameters>
		
		
		<asp:ControlParameter  ControlID="grdStores"  Name="StateId" PropertyName="SelectedValue"   Type="Int16" />
		
 
	</UpdateParameters>
</asp:SqlDataSource>

Open in new window

Avatar of Oliver Amaya
Oliver Amaya
Flag of Venezuela, Bolivarian Republic of image

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

Open in new window

Avatar of barnesco
barnesco

ASKER

That's what I thought, too. But when I did, I received an error: Cannot insert a NULL value.
ASKER CERTIFIED SOLUTION
Avatar of Oliver Amaya
Oliver Amaya
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found the answer: I need to insert the DataKeyNames="StoreID" in the DetailsView.