Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selectedvalue on ddl when db shows Null

Status
Not open for further replies.

kaijanm

Programmer
May 14, 2003
102
US
Hello. Thanks in advance.

I have several places on my site where there is a drop down list that is populated by the results of a stored procedure on SQL Server (so sproc returned list such as
Male
Female
)

and then another sproc is called to look up the info on a person and then as I check the info, I need to select the item in the list that corresponds to the value from the second sproc call.
So I call second sproc and get john doe who is marked as a male.
and I want the DDL to have Male selected. In the case where I have someone who hasn't yet had their gender selected, I want it to show nothing.

My current code (broken) to do this is:
If rdrUser.item("gender") is system.dbnull.value Then
ddlGender.selecteditem.text = ""
Else
'figure out what they are and make the right selection

What this does is blank out the first (normally) item so my list is then just

*Blank*
Female

Is there something I should do instead of ddl.selecteditem.text = ""

Thank you again!
 
First: Fill the dropdown and then add a blank as follows:

With ddl1
.DataSource = sqlDR
.DataTextField = "Gender"
.DataBind()
.Items.Insert(0, New ListItem)
.SelectedIndex = 0
End With

Then, when you are ready to make your selection do the following:

With ddl1
.SelectedIndex = .Items.IndexOf(.Items.FindByText("Gender"))
End With

Substitue "Gender" for whatever you want the text to say; i.e. "Male", "Female", or ""

HTH

Eva
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top