[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

dropdown list in a formview

Posted on 2007-03-27
15
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 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