Saturday, March 24, 2012

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

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,
-MikeHi-
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
On Wed, 07 Jul 2004 16:21:47 GMT, Mike Bridge <mike@.bridgecanada.com>
wrote:

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

0 comments:

Post a Comment