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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownList control

Status
Not open for further replies.

virtualranger

Technical User
Sep 14, 2001
115
GB
I have a ddl populated with some userID's from a dataset taken from my user table. I have also added the Listitem 'All' manually. When users visit the page I need the DDL selectedindex to default to their own user initials if there is a match, if not it should default to 'All' . The userID and userinitials are both stored in the users session - session("userID") and session("userinitial").

This is the code so far to populate the ddl and it works fine:

Dim myJob As New Business.Jobs()
Dim dsUsers As DataSet = myJob.GetUsers
Dim myListItem As New ListItem()

ddlUser.DataSource = dsUsers.Tables(0).DefaultView
ddlUser.DataTextField = "userInitials"
ddlUser.DataValueField = "userID"
ddlUser.DataBind()
myListItem.Text = "All"
myListItem.Value = 0
ddlUser.Items.Add(myListItem)

Now I need to see if the current users ID is in the ddl so it can default to that item. Can the item 'All' be added as the first item in the ddl instead of the last? I've tried it but it gets overwritten when the content of the dataset is added to the ddl. If it was possible then I could just use the following piece of code so that when there is no match it defaults to the first item in the ddl:

ddlUser.SelectedIndex = ddlUser.Items.IndexOf(ddlUser.Items.FindByValue(Session("userID")))

If I can't add it as the first item how do I search the ddl for either the users initials or userID to set the default indexitem?

Any ideas?

Thanks,
Jamie
 
To add an Item in a particular place, use the Items.Insert method rather than Items.Add


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top