Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filling DropDownList, but getting error when selected value is 0

Posted on 2006-07-10
8
Medium Priority
?
196 Views
Last Modified: 2006-11-18
Hi there,

I'm trying to fill a dropdownlist in a datagrid and I'm running into an error:

"Specified argument was out of the range of valid values. Parameter name: value "

When the value of the dropdownlist is 0.

Here's my aspx:
asp:DropDownList
Enabled="false"
ID="dropStates"                                                       
DataTextField="State_Acronym"
DataValueField="ID"
DataSource="<%# Load_States() %>"
SelectedValue='<%# Container.DataItem("State") %>'

here's my code-behind:

Public Function Load_States()
            Dim cmdSelect As SqlCommand
            Dim dtrStates As SqlDataReader
            Dim strSelect AS string
            Dim ddlDataSet as DataSet = New DataSet()
            Dim conPubs As New SqlConnection(ConfigurationSettings.appSettings("sqlconnectionString"))
            
            strSelect = "Select tblStates.* From tblStates"
            Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(strSelect, conPubs)  
            
            myDataAdapter.Fill(ddlDataSet, "Categories")
       
            Return ddlDataSet            
End Function

There's no value in the tblStates with a 0 so that's what's throwing the error.  Any thoughts on how to get this work?

Full Williams                                                      
                                                      Runat="Server" />
0
Comment
Question by:FullWilliams
[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 Comments
 
LVL 5

Expert Comment

by:bastibartel
ID: 17072828
Hi FullWilliams,

Try selecting 1.
As far as I remember VB has 1-based arrays.

Cheers!
0
 
LVL 7

Expert Comment

by:RainMan82
ID: 17073065
yeah bastibartel is correct....they are all 1-based....
0
 

Author Comment

by:FullWilliams
ID: 17073725
Selecting 1 would be the first state though and that's not correct.  Also, would I select it in the code or in the aspx?
0
Independent Software Vendors: 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:FullWilliams
ID: 17073817
I tried putting in:

myDataAdapter.SelectedValue = 0
 and got this error:

BC30456: 'SelectedValue' is not a member of 'System.Data.SqlClient.SqlDataAdapter'
0
 

Author Comment

by:FullWilliams
ID: 17073841
increasing the points as I need to get this resolved.
0
 

Author Comment

by:FullWilliams
ID: 17074185
I got it to by modifying my code behind:

myDataAdapter.Fill(ddlDataSet, "Categories")

        'adding a row
        dim row as datarow
        row = ddlDataSet.tables("Categories").newrow
        row("State_Acronym") = ""
        row("ID") = 0  
       
        ddlDataSet.tables("Categories").rows.add(row)

Please close this question
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17325331
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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