?
Solved

Need to update data from dropdown list in DetailsView

Posted on 2007-11-26
4
Medium Priority
?
728 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:Oliver Amaya
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:
Oliver Amaya earned 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

850 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