Solved

Need to update data from dropdown list in DetailsView

Posted on 2007-11-26
4
721 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:barnesco
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:joex911
ID: 20350653
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

0
 

Author Comment

by:barnesco
ID: 20351415
That's what I thought, too. But when I did, I received an error: Cannot insert a NULL value.
0
 
LVL 10

Accepted Solution

by:
joex911 earned 500 total points
ID: 20351478
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

0
 

Author Comment

by:barnesco
ID: 20355389
I found the answer: I need to insert the DataKeyNames="StoreID" in the DetailsView.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.net pdf file opening in debug mode but not on web 13 32
How do see the validation errors on ASP.NET MVC 4 37
Hidden Field Value 10 57
Json and asp.net mvc 2 43
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now