Specificed arguement was out of range of valid values.

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi all,

Have filled a dropdown list with data directly from the database. Wish to have a specific value selected when the page first loads. I am using the following line of code:
Code:
ddlOrgtype.DataSource = dsOrgTypes
ddlOrgtype.DataTextField = "OrgType"
ddlOrgtype.DataValueField = "Identifier"
ddlOrgtype.DataBind()
ddlOrgtype.selectedValue = "Select Organisation Type"

I am getting the error: "Specificed arguement was out of range of valid values.", any suggestions on how to overcome this problem?

Mike55
 
mark007 said:
Make sure "Select Organisation Type" is a possible value.


Yep, its a value that exists in the drop down. Got around the problem by using the following code:
Code:
Me.ddlOrgtype.Items(6).Selected() = True
Possible not the best way to do it, but still it works

Mike55
 
mark007 said:
Are you sure it was a value and not just the displayed text?

You can't set selected "value" by specifying a text value. If you wanted to set it by a text value you'd need to use this:

ddl.SelectedItem.Text = "Select Organisation Type"
 
Back
Top