Avatar of vthunder70
vthunder70

asked on 

dropdown list in a formview

Hello experts,
I am developing a form for updating purposes using the FormView. I am using data from one tabel only, it works great using the form without altering anything in it. But there are question on the form such as: "do you need a construction permit? and the answer is yes or no" I will like to use a drop down list in this fields instead of typying yes or no in a text box.
This is very important so that's why I am giving a lot of points
I can not get this drop down list to work. it keeps giving me an error saying: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
ASP.NET

Avatar of undefined
Last Comment
vthunder70
Avatar of here4u247
here4u247

did you use something like this in your dropdownlist

SelectedValue='<%# Bind("yesornofield") %>'


make sure yesornofield has default value so it always has a value to select on load!

hope that makes sense..

Avatar of here4u247
here4u247

the way i do n-tier apps at moment or as i understand is, the most data manipulation is done in business layer using pre populated business objects/collections and then passed/used in the presentation layer. each layer makes calls to previous layer only, i.e.

data -- Data Access
Data Access -- Bus Layer
Bus Layer - Presentation layer

thus your app will be platform independent, i.e. if you want to change from winform to webform you only need to modify the presentation layer, or database you only change DAL layer etc..

it will be great to get views of other experts on this.

abs
Avatar of here4u247
here4u247

^

please ignore my last post, i posted it on the wrong questions


sorry!
Avatar of vthunder70
vthunder70

ASKER

Yes i have the SelectedValue='<%# Bind("yesornofield") %>' in my case the name of my field is "followup".  This field on my database is set to null... is that what you mean by...."make sure yesornofield has default value so it always has a value to select on load!"

Avatar of here4u247
here4u247

yep thats what i mean...
Avatar of vthunder70
vthunder70

ASKER

so i should put a defalult value in my database table colum?
Avatar of vthunder70
vthunder70

ASKER

Hi experts,
I could really use the help with this problem. I looked at previous question like this one and they are all without an aswer I could use.

Thanks,
Avatar of here4u247
here4u247

hey bud, did you try my suggestion?!
Avatar of vthunder70
vthunder70

ASKER

I guess I don't understand what you mean... do I need to put a value of "Yes" or "No" in my database table as a default?

thanks,
ASKER CERTIFIED SOLUTION
Avatar of here4u247
here4u247

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of vthunder70
vthunder70

ASKER

Hi,
It's given me the same error....

==========================================================================
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
==========================================================================

This is my drop down lit
<EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("permits") %>' DataTextField="NO" DataValueField="0">
                            <asp:ListItem Selected="True" Value="1">Yes</asp:ListItem>
                            <asp:ListItem Value="2">No</asp:ListItem>
                        </asp:DropDownList>

                    </EditItemTemplate>

Thanks,
Avatar of here4u247
here4u247

as i said earlier <%# Bind("permits") %> should be 1 or 2 at all time,  therefore check permits column if it contains values other than 1 or 2...
Avatar of vthunder70
vthunder70

ASKER

Hi here4u247,
I'm actually embarrased to tell you that I am still getting the same error. I am missing what you mean by
===============================================================================
as i said earlier <%# Bind("permits") %> should be 1 or 2 at all time,  therefore check permits column if it contains values other than 1 or 2...
================================================================================
Did you mean check the permit column in my database? I did that, i put a default value of 1... and that didn't work... I get the same error
Where exactly do I check for the <%#Bind("permits")%> value to make sure is set for 1 or 2?
Thank you for all your help!
Avatar of here4u247
here4u247

thats no prob vthunder70, so the permits column is defaulted to value of 1, which is good, so it could be data issue, so check in permits column if any row has any value other than 1/2, you can do that by querying the db, i.e.:

select * from [TABLENAME] where permits <> 1 or permits <> 2

and see if it brings any results...


cheers,

abdi
Avatar of vthunder70
vthunder70

ASKER

Hi Abdi,
Thanks for your help and your time!
I delete the column and added it again I use the default value = 1 and it worked!! then I went one step further and change my data type to vchar and wrote default value = NO and change my values in my dropdownlist and IT WORKED TOO!!!

thanks again
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo