[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

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
0
vthunder70
Asked:
vthunder70
  • 8
  • 7
1 Solution
 
here4u247Commented:
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
 
here4u247Commented:
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
 
here4u247Commented:
^

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


sorry!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
vthunder70Author Commented:
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
 
here4u247Commented:
yep thats what i mean...
0
 
vthunder70Author Commented:
so i should put a defalult value in my database table colum?
0
 
vthunder70Author Commented:
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
 
here4u247Commented:
hey bud, did you try my suggestion?!
0
 
vthunder70Author Commented:
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
 
here4u247Commented:
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
 
vthunder70Author Commented:
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
 
here4u247Commented:
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
 
vthunder70Author Commented:
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
 
here4u247Commented:
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
 
vthunder70Author Commented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now