virtualranger
Technical User
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
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