468,765 Members | 1,475 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

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 7631
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by CARIGAR | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.