Link to home
Start Free TrialLog in
Avatar of kdeutsch
kdeutschFlag for United States of America

asked on

Check drop down list for value

I need to check my drop down list for a value before I assign it the myDatatablerow,  I have some instances where its not loading the data because its no longer there.

So what I do is load my ddlrecrutier dropdownlist on the page load and tehn i pull information about a person, but if there recruiter no longer exists it bombs out on the assigning of the recruit data to the dropdownlist, how can i check to see if recruiter is in list and it not assign it to zero, to make them pick a recruiter.

This is spot where is this number is not in the dropdownload it bombs out on me with this error

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

ddlRecruiter.SelectedValue = myDataTable.Rows(0)(23)

Meaning that persons recrutier is not in the page load of recruiters, so i need to check to see if its existing in the dropdown and if so then assign it else assign it to zero.



I do this on page load 

Private Sub LoadRecruiters()
        sql = "Select r.intRecruiterRecordID, w.strFullName from tblRecruiter as r INNER JOIN WORSDotNet.dbo.tblUser as w on w.intID = r.intRecruiterID where r.bitActive = 1 Order by " _
            & "strFullName, intTeamID"

        ddlRecruiter.Items.Add(New ListItem("Pick Recruiter", "0"))
        buildDD(sql, ddlRecruiter)

    End Sub

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

try

dim selRec as string = myDataTable.Rows(0)(23)
if ddlRecruiter.Items.Items.IndexOf(selRec) <> -1 then
  ' assign
else
  ' assign to 0
end if
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kdeutsch

ASKER

Ok,

Heres waht i have but I get blue underlines under the not nothing protion, still a vb.net 1.1 project

 Dim selRec As String = myDataTable.Rows(0)(23)

        Dim I As ListItem = ddlRecruiter.Items.FindByValue(selRec)
        If I Is Not Nothing Then
            ddlRecruiter.SelectedValue = myDataTable.Rows(0)(23)
        Else
            ddlRecruiter.SelectedValue = "0"

        End If
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can do it other way also as following

If Not  IsNothing(I) Then
All,

Ok I got it working by the following, but if they hit refresh on the page I get this error which calls out the Dim line

 Dim I As ListItem = ddlRecruiter.Items.FindByValue(myDataTable.Rows(0)(23))

        If I Is Nothing Then
            ddlRecruiter.SelectedValue = "0"
        Else
            ddlRecruiter.SelectedValue = myDataTable.Rows(0)(23)
        End If


Object not set to reference, why would it get this.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
all,

Ok Figured it out had it outside of my postback statment.
Thanks