Dropdownlist Error

R

renor321

Hello,

I've searched the groups unsuccessfully to the solution to this
problem. I've seen a few others making note of it, but it didn't seem
like there were any solutions.

I have a drop down list in vb.net, and when I do a DataBind on it, I
get an error "The 'SelectedIndex' and 'SelectedValue' attributes are
mutually exclusive." Basically, this doesn't happen all the time-It
happens after certain specific events take place. This seems to happen
only when data is re-binded to the page.

The code where this happens is as follows:
ddlVersionList.DataSource =
dsProductVersionList.Tables("ProductVersionList")
ddlVersionList.DataTextField = "Version"
ddlVersionList.DataValueField =
"PDP__Product_Version_ID"
ddlVersionList.DataBind()

I'm totally lost, since I'm not doing anything with the SelectedIndex
and SelectedValue until after the DataBind. I'm also clearing the drop
down list prior to executing this code.

Any suggestions would be greatly appreciated.

Thanks!

-Dave-
 
G

Guest

I've been fighting the exact same problem, using .DataBind() to populate the
Items collection of a DropDownList control that already has data in it, even
though i call .ClearSelection() and .Items.Clear() before calling
..DataBind().

In my case I wasn't binding it to a DataTable, but instead it was in a
generic procedure that accepts an ICollection object and the two property
names and binds the control to that.

I couldn't find a solution (I think its just a bug in the DataBind method),
but to work around it i created another generic procedure that takes the
ICollection object and property names and using reflection builds a
ListItem() array that can then be used to populate the DropDownList using the
Items.AddRange() method. This works just fine with no errors. You could
probably create a similar procedure to access the rows and columns of the
table, and return a ListItem() collection.

Rae
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top