473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

dropdownlist in FormView "has a SelectedValue which is invalid"

In my Registrant FormView I have a DropDownList which loads data from a
secondary SqlDataSource "sdsOfficeParks". I need the user to select an office
park but save the selected value in the FormView's ObjectDataSource
"odsRegistrant" .

The following solution can't work because I need the ddl selected value
bound to my odsRegistrant but both tables have the same column name for
primary key.

<asp:DropDownList ID="ddlOfficePark" runat="server" CssClass="waDdl"
Width="202px"
DataSourceID="sdsOfficePark" DataTextField="OfficeParkName"
DataValueField="OfficeParkId"
SelectedValue='<%# Bind("OfficeParkId")%>' >

<asp:SqlDataSource ID="sdsOfficePark" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:myDB %>"
SelectCommand="Select OfficeParkName, OfficeParkId from dbo.OfficePark
order by OfficeParkName ">
</asp:SqlDataSource>

<asp:ObjectDataSource ID="odsRegistrant" runat="server"
TypeName="RegistrantDB"
DeleteMethod="DeleteRegistrant" InsertMethod="InsertRegistrant"
SelectMethod="GetRegistrant"
UpdateMethod="UpdateRegistrant" DataObjectTypeName="RegistrantDetails" >
<UpdateParameters>
<asp:Parameter Name="officeParkId" Type="Int32"/>
....

Note that for most rows in the database the OfficeParkId is 0 and there is
no zero entry in the ddl. Could this be the problem and how do I load a
(choose one) entry before the data is loaded?

Thanks for any ideas.
Apr 13 '06 #1
2 7878
Good Morning Dabbler,

Blessed Good Friday to you and the readers.

In the demo on my website I explained how I used the AppendDataBoundItems
property to set a ListItem with null value as the default within the
InsertItemTemplate.

<%-- when we insert a new record there is no country value to be bound upon
displaying the empty record. Therefore let's add a default listitem with a
null
value so that we can validate it using a RequiredFieldValidator to ensure that
the user will enter a value in it. I will use here the AppendDataBoundItems
property of the dropdownlist so that any databound items to be created will
not
replace the default listitem that I just created. --%>
<asp:DropDownList ID="ddlCountry" runat="server" DataSourceID="odsCountries"
AutoPostBack="True"
SelectedValue='<%# Bind("Country") %>' AppendDataBoundItems="true">
<asp:ListItem Value="">Select a Country</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ForeColor="white" ID="valddlCountry"
runat="server"
ErrorMessage="Cannot leave the country blank"
Text="*" Display="Dynamic"
ControlToValidate="ddlCountry">
</asp:RequiredFieldValidator>

Let me know if this strategy solved the problem you had or not. May be I
did not fully understand it.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
In my Registrant FormView I have a DropDownList which loads data from a
secondary SqlDataSource "sdsOfficeParks". I need the user to select an office
park but save the selected value in the FormView's ObjectDataSource
"odsRegistrant" .

The following solution can't work because I need the ddl selected value
bound to my odsRegistrant but both tables have the same column name for
primary key.

<asp:DropDownList ID="ddlOfficePark" runat="server" CssClass="waDdl"
Width="202px"
DataSourceID="sdsOfficePark" DataTextField="OfficeParkName"
DataValueField="OfficeParkId"
SelectedValue='<%# Bind("OfficeParkId")%>' >

<asp:SqlDataSource ID="sdsOfficePark" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:myDB %>"
SelectCommand="Select OfficeParkName, OfficeParkId from dbo.OfficePark
order by OfficeParkName ">
</asp:SqlDataSource>

<asp:ObjectDataSource ID="odsRegistrant" runat="server"
TypeName="RegistrantDB"
DeleteMethod="DeleteRegistrant" InsertMethod="InsertRegistrant"
SelectMethod="GetRegistrant"
UpdateMethod="UpdateRegistrant" DataObjectTypeName="RegistrantDetails" >
<UpdateParameters>
<asp:Parameter Name="officeParkId" Type="Int32"/>
...

Note that for most rows in the database the OfficeParkId is 0 and there is
no zero entry in the ddl. Could this be the problem and how do I load a
(choose one) entry before the data is loaded?

Thanks for any ideas.

Apr 14 '06 #2

Thanks for your good wishes and yes, your suggestion did the trick!

"Phillip Williams" wrote:
Good Morning Dabbler,

Blessed Good Friday to you and the readers.

In the demo on my website I explained how I used the AppendDataBoundItems
property to set a ListItem with null value as the default within the
InsertItemTemplate.

<%-- when we insert a new record there is no country value to be bound upon
displaying the empty record. Therefore let's add a default listitem with a
null
value so that we can validate it using a RequiredFieldValidator to ensure that
the user will enter a value in it. I will use here the AppendDataBoundItems
property of the dropdownlist so that any databound items to be created will
not
replace the default listitem that I just created. --%>
<asp:DropDownList ID="ddlCountry" runat="server" DataSourceID="odsCountries"
AutoPostBack="True"
SelectedValue='<%# Bind("Country") %>' AppendDataBoundItems="true">
<asp:ListItem Value="">Select a Country</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ForeColor="white" ID="valddlCountry"
runat="server"
ErrorMessage="Cannot leave the country blank"
Text="*" Display="Dynamic"
ControlToValidate="ddlCountry">
</asp:RequiredFieldValidator>

Let me know if this strategy solved the problem you had or not. May be I
did not fully understand it.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
In my Registrant FormView I have a DropDownList which loads data from a
secondary SqlDataSource "sdsOfficeParks". I need the user to select an office
park but save the selected value in the FormView's ObjectDataSource
"odsRegistrant" .

The following solution can't work because I need the ddl selected value
bound to my odsRegistrant but both tables have the same column name for
primary key.

<asp:DropDownList ID="ddlOfficePark" runat="server" CssClass="waDdl"
Width="202px"
DataSourceID="sdsOfficePark" DataTextField="OfficeParkName"
DataValueField="OfficeParkId"
SelectedValue='<%# Bind("OfficeParkId")%>' >

<asp:SqlDataSource ID="sdsOfficePark" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:myDB %>"
SelectCommand="Select OfficeParkName, OfficeParkId from dbo.OfficePark
order by OfficeParkName ">
</asp:SqlDataSource>

<asp:ObjectDataSource ID="odsRegistrant" runat="server"
TypeName="RegistrantDB"
DeleteMethod="DeleteRegistrant" InsertMethod="InsertRegistrant"
SelectMethod="GetRegistrant"
UpdateMethod="UpdateRegistrant" DataObjectTypeName="RegistrantDetails" >
<UpdateParameters>
<asp:Parameter Name="officeParkId" Type="Int32"/>
...

Note that for most rows in the database the OfficeParkId is 0 and there is
no zero entry in the ddl. Could this be the problem and how do I load a
(choose one) entry before the data is loaded?

Thanks for any ideas.

Apr 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Morris | last post by:
I'm new to .NET and just trying a few things out, like emailing. I created a form in Visual Studio .Net to input some information for generating an email and I'm getting the following error when it...
1
by: Ron | last post by:
I am trying to run asp.net pages. The server is accessed via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and asp.net page I...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
0
by: Winterminute | last post by:
I am trying to read a list of install programs using WMI with ASP.NET/C#. However, it fails with "Invalid Class". I have confirmed that if I query LOCALHOST then it works fine, but if I query a...
2
by: Vinod I | last post by:
Hi Team, When I tryed following code, I am getting the Runtime Error as "The View State is invalid for this page and might be corrupted." Exception Details: System.Web.HttpException: The View...
2
by: Brent | last post by:
Here's my function: public void getInterestLevelDDL(string co_interest_level) { sql = ; //get_select_list creates a valid ICollection datatable ctrlDDL_CIL.DataSource =...
71
by: Greg | last post by:
Is it your general opinion that C# is generally designed/intended/ready to replace C++? I know the answer is not black and white but please repond YES or NO (add any comments if you would like) ...
1
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.