473,224 Members | 1,292 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,224 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 7868
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:...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.