?
Solved

Need to update data from dropdown list in DetailsView

Posted on 2007-11-26
4
Medium Priority
?
725 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

801 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