Strange error binding DataTable to DropDownList: out of range... Parameter name: value

M

Mike Bridge

I'm getting a nonsensical error when binding a DataTable with one row
to a DropDownList.

The DataTable's row contains the fields "id" (INT), "description"
(VARCHAR) and with a couple other unused fields.

I'm binding the table in code behind:

DataTable table=Publishinggroup.GetPublisheegroups(person.Id);
ddlPublishSource.DataSource=table;
ddlPublishSource.DataBind();

And in the aspx page, it's:

<asp:DropDownList ID="ddlPublishSource" runat="server"
DataValueField="id" DataTextField="description" />

But the error that occurs on the DataBind() command is nonsensical,
because there are no column names and no values with a value of
"value":

Specified argument was out of the range of valid values. Parameter
name: value

Any ideas on what might cause that?

Thanks,

-Mike
 
M

Mike Bridge

Hi-

Ok, I found the problem---the drop down list was having a value
preselected, before the datasource was assigned, but that value was no
longer in the datatable. That was why the bind was failing.

-Mike
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top