Solved

dropdown list in a formview

Posted on 2007-03-27
15
285 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:vthunder70
  • 8
  • 7
15 Comments
 
LVL 7

Expert Comment

by:here4u247
ID: 18799914
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..

0
 
LVL 7

Expert Comment

by:here4u247
ID: 18800016
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
0
 
LVL 7

Expert Comment

by:here4u247
ID: 18800023
^

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


sorry!
0
 

Author Comment

by:vthunder70
ID: 18800252
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!"

0
 
LVL 7

Expert Comment

by:here4u247
ID: 18800459
yep thats what i mean...
0
 

Author Comment

by:vthunder70
ID: 18800520
so i should put a defalult value in my database table colum?
0
 

Author Comment

by:vthunder70
ID: 18807704
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,
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Expert Comment

by:here4u247
ID: 18808114
hey bud, did you try my suggestion?!
0
 

Author Comment

by:vthunder70
ID: 18809882
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,
0
 
LVL 7

Accepted Solution

by:
here4u247 earned 500 total points
ID: 18816227
sorry i wasn't clear, to avoid any errors you need to make sure SelectedValue that you are passing when you binding the formview exists in list of item inside the dropdownlist.

i.e. if you have dropdownlist of Yes / NO inside your formview:


<formview..
...
 <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("yesornofield") %>'>
                <asp:ListItem Selected="True" Value="1">Yes</asp:ListItem>
                <asp:ListItem Value="2">No</asp:ListItem>
            </asp:DropDownList
..
</formview>

if you have visual studio, you can go to edit template in the formview, left click the dropdownlist you want to bind, click edit databindings, then choose which field to select as SelectedValue....

the important thing to remember is you may get an error <%# Bind("yesornofield") %> is null for example, so make sure you have default value for yesornofield for example 0 that way it will always default t NO when no data is there.

hope that make sense!


0
 

Author Comment

by:vthunder70
ID: 18819083
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,
0
 
LVL 7

Expert Comment

by:here4u247
ID: 18819655
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...
0
 

Author Comment

by:vthunder70
ID: 18822948
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!
0
 
LVL 7

Expert Comment

by:here4u247
ID: 18823026
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
0
 

Author Comment

by:vthunder70
ID: 18823285
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
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now