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

I am getting this error:
Specified argument was out of the range of valid values. Parameter name: value

when i try to populate a DDL with a preselected value...
the code that (i THINK) is relevant is:

Sub Page_Load(Sender As Object, E As EventArgs)
           Dim ConnectToDatabase as new SQLConnection("UID=SA;PWD=hello; Data Source=(local); database=builders;")
           Dim DDLAdapterStatus as new SQLDataAdapter("SELECT * from tbl_status",connecttodatabase)
           Dim DS1 as new Dataset
           Dim DDLAdapterProperty as new SQLDataAdapter("SELECT DISTINCT RTRIM(ISNULL(address1, '')) + ' ' + RTRIM(ISNULL(address2, '')) AS title, propertyID FROM tbl_property",connecttodatabase)
           Dim DS2 as new Dataset
           Dim DDLAdapterCalltype as new SQLDataAdapter("SELECT * from tbl_calltype",connecttodatabase)
           Dim DS3 as new Dataset

           DDLAdapterStatus.Fill(Ds1, "status")
           DDLAdapterProperty.Fill(Ds2, "property")
           DDLAdapterCalltype.Fill(Ds3, "calltype")
If Not IsPostBack Then

           jobID = Trim(request.querystring("jobID"))
           Row = ClassyDS.Tables("Jobs").Rows(0)
           jobtitle.Text = Row.Item("jobtitle").ToString()
           jobdescription.Text = Row.Item("jobdescription").ToString()
           began.Text = Row.Item("began").ToString()
           enddate.Text = Row.Item("enddate").ToString()
           extensiondate.Text = Row.Item("extensiondate").ToString()
           drawingref.Text = Row.Item("drawingref").ToString()

                    ddlstatus.DataSource = Ds1               '<--- (Dataset Name)
                    ddlstatus.DataMember = "status"               '<--- (Table Name)
                    ddlstatus.DataTextField = "statusname"               '<---    (Column Name)
                    ddlstatus.DataValueField = "statusid"               '<--- (Column Name)
                    ddlStatus.SelectedValue = Row.Item("statusid")

                    ddlproperty.DataSource = Ds2               '<--- (Dataset Name)
                    ddlproperty.DataMember = "property"               '<--- (Table Name)
                    ddlproperty.DataTextField = "title"               '<---    (Column Name)
                    ddlproperty.DataValueField = "propertyid"               '<--- (Column Name)
                    ddlproperty.SelectedValue = Row.Item("propertyid")

                    ddlcalltype.DataSource = Ds3               '<--- (Dataset Name)
                    ddlcalltype.DataMember = "calltype"               '<--- (Table Name)
                    ddlcalltype.DataTextField = "typename"               '<---    (Column Name)
                    ddlcalltype.DataValueField = "typeid"               '<--- (Column Name)
                    'ddlcalltype.SelectedValue = Row.Item("calltype")  '<-----------THIS IS THE LINE THAT IS CAUSING PROBLEMS

       End If
Sub GetJob(JobID As Integer)
       SelectStatement = "Select * From tbl_job Where jobid =" & JobID
       ConnectString = "Provider=SQLOLEDB; UID=SA;PWD=hello; Data Source=(local); database=builders;"
       Connect.ConnectionString = ConnectString
       Adapter.SelectCommand =  new OleDbCommand(SelectStatement, Connect)
       ClassyCB  = New OleDbCommandBuilder(Adapter)
 End Sub

The field in tbl_job i want to use as the preselected field is called "Calltype". When i comment out this line the page works fine...

any ideas? let me know if you need more info

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if already one is selected, setting like this would give error
ddlcalltype.SelectedValue = Row.Item("calltype")  

u can use like this
ddlcalltype.SelectedIndex = - 1
ddlcalltype.SelectedValue = Row.Item("calltype")  

stringvariable = Convert.ToString(Row.Item("calltype"))
ddlcalltype.selectedindex =  ddlcalltype.Items.IndexOf(ddlcalltype.Items.FindByValue(stringvariable))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lz7cjcAuthor Commented:
would you mind explaining to me why that is the case for this drop down list only? whilst i try the code you have given me
lz7cjcAuthor Commented:
i get the same error with the first suggestion and the second doesn't choose the right item in the ddl
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

I believe you are getting this error, because you are trying to set a selected value for a value that doesn't exist, or you are trying to select the value of the the type using the type name.

Try changing
ddlcalltype.SelectedValue = Row.Item("calltype")  
ddlcalltype.SelectedText = Row.Item("calltype")

Or change:
ddlcalltype.SelectedValue = Row.Item("calltype")  
ddlcalltype.SelectedValue = Row.Item("typeid")
lz7cjcAuthor Commented:
thanks - i have merged your two answers and it now works... what worries me is that there is no reason i can think of why the numbering is out by one - any thoughts? obviously i don't want to cover up one bug with a seperate fix
                    stringvariable = Convert.ToString(Row.Item("calltype"))
                    ddlcalltype.selectedindex =  stringvariable - 1

lz7cjcAuthor Commented:
calltype is storing a number... that is the same as typeid as a foreign key... i appreciate this is pretty bad coding practice but it is down to a lack of planning and i would rather not change now!
I'm not sure why your index is off by one. Perhaps you should open a new question regarding that issue since this question is resolved?
dropdown list index is zero based index

if u had the drop down list like


then ddname.selectedindex = 0 selects value 1
ddname.selectedindex = 1 selects value 2

use only if the value is going to be sequential without any gaps

ddlcalltype.selectedindex =  stringvariable - 1

best practise would be always

ddlcalltype.SelectedIndex = - 1 ' resets the selected index, if was preselected
'if you want to select by value
        If Not ddlcalltype.Items.FindByValue(Convert.ToString(Row.Item("calltype"))) Is Nothing Then
          ddlcalltype.SelectedValue = Convert.ToString(Row.Item("calltype"))
        End If
' or if you want to select by text
        If Not ddlcalltype.Items.FindByText(Convert.ToString(Row.Item("calltype"))) Is Nothing Then
          ddlcalltype.SelectedText = Convert.ToString(Row.Item("calltype"))
        End If
 here you check if the value or text exists in the dropdown list

or simply use

ddlcalltype.SelectedIndex = - 1 ' resets the selected index, if was preselected
ddlcalltype.SelectedIndex = ddlcalltype.Items.IndexOf(ddlcalltype.Items.FindByValue(stringvariable))
ddlcalltype.SelectedIndex = ddlcalltype.Items.IndexOf(ddlcalltype.Items.FindByText(stringvariable))
lz7cjcAuthor Commented:
thanks for your help on this - and thanks for the explanation
all the best
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.