Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 26th, 2006, 01:54 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default dropdownlist value into detailsview: how?

Hi,

I have a detailsview for inserting data, and a dropdownlist which
selectedValue must be used to fill one of the field of the detailsview.
Table 'pc' is related to table 'lok'.

I tried a lot of things, but still without succes. Here are the two methods
i tried with two different errors. It works only when i introduce directly a
value in "DefaultValue" (see below)

Thanks for any help
André


1) first method:
asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
...
InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
<InsertParameters>
<asp:Parameter Name="na" Type="String" />
<asp:Parameter Name="ty" Type="String" />
</InsertParameters>
....
Code-behind:
 Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
lok = DropDownList1.SelectedValue
SqlDataSource1.InsertParameters.Add("lok", lokl)
End Sub

This gives: No value given for one or more required parameters
----------------------------------------------------------------------------
-------------------------
2) second method
asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
...
InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
<InsertParameters>
<asp:Parameter Name="na" Type="String" />
<asp:Parameter Name="ty" Type="String" />
<asp:Parameter Name="lok" Type="String" DefaultValue="<%=lok %>" />
</InsertParameters>
...

Code-behind:
 Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
lok = DropDownList1.SelectedValue
End Sub

This gives: You cannot add or change a record because a related record is
required in table 'lokl'
which means in fact that the value of the parameter is not passed!

It works when i give directly a value: <asp:Parameter Name="lok"
Type="String" DefaultValue="1-45" />







Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing DropDownList in DetailsView firblazer ASP.NET 3.5 Basics 2 June 21st, 2008 06:48 AM
Cannot bind from DropDownList to DetailsView kiekar ASP.NET 2.0 Basics 0 February 19th, 2008 09:26 PM
Re-Binding A Dropdownlist In A DetailsView cyber0ne BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 March 26th, 2007 07:10 PM
Linking two Dropdownlist in DetailsView tna55 ASP.NET 2.0 Basics 0 February 12th, 2007 10:29 AM
DropDownList in side the DetailsView ndc550 ASP.NET 2.0 Basics 0 October 19th, 2006 05:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.