Showing posts with label parameter. Show all posts
Showing posts with label parameter. Show all posts

Saturday, March 24, 2012

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

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.

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.

Tuesday, March 13, 2012

Strange problem

I have a class method which takes integer as parameter...when i call the
method as shown below i get this error message: Specified cast is not valid
<td><%# bs.getPriority((int)DataBinder.Eval(Container.DataItem,
"Priority"))%></td>
When i print the DataItem "Priority" it shows an integer value, but for some
reason the method does not like value.. if i call this method like ->
bs.getPriortiy(3); it works fine.
In the database i have a field called "Priority" int type...
The method works fine when i call it in DataItemBound method..
any idea?Hi,
Try using
int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.
Tod Birdsall, MCP
http://tod1d.blogspot.com
Tod thank you so much :) it worked..
still why one of them works not the other as shown below:
<TD><%# bs.getCampusName((int)DataBinder.Eval(Container.DataItem,
"CampusID"))%></TD>
<td><%# bs.getCampusName((int.Parse(DataBinder.Eval(Container.DataItem,
"Priority")))%></td>
both CampusID and Priority is same type of value..
Many Thanks again.
"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Sorry that did not solve the problem... :( i am getting this error message
now:
The best overloaded method match for 'int.Parse(string)' has some invalid
arguments
"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Acutally, DataBinder.Eval returns an object unless you pass a third
parameter, a format specifier, i.e.
DataBinder.Eval(Container.DataItem, "Priority", "{0:d}")
Otherwise you get an object reference back, in which case you could
use Convert.ToInt32
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 9 Nov 2004 07:38:03 -0800, "huzz"
<huzz@.discussions.microsoft.com> wrote:
>Sorry that did not solve the problem... :( i am getting this error message
>now:
>The best overloaded method match for 'int.Parse(string)' has some invalid
>arguments
>"Tod Birdsall" wrote:
>
Hi,
Scott is correct. Sorry for the mis-information.
I tried to reproduce your error message. I created a function in the
code behind like so:
protected string GetRemainderInEscrow(decimal approvedAmount, object
paidAmount)
I then called the method from the aspx page using the following code :
<%# GetRemainderInEscrow( (decimal)DataBinder.Eval(Container,
"DataItem.ApprovedAmount"), DataBinder.Eval(Container, "DataItem.Paid")
) %>
The code worked as it should. If you have control over the
'bs.getPriority' method, try allowing an object to be passed instead of
an integer value type. If that doesn't work. If that still does not
work, copy and paste the exact error message and Stack Trace.
Tod Birdsall, MCP
http://tod1d.blogspot.com

Strange problem

I have a class method which takes integer as parameter...when i call the
method as shown below i get this error message: Specified cast is not valid

<td><%# bs.getPriority((int)DataBinder.Eval(Container.Data Item,
"Priority"))%></td
When i print the DataItem "Priority" it shows an integer value, but for some
reason the method does not like value.. if i call this method like ->
bs.getPriortiy(3); it works fine.

In the database i have a field called "Priority" int type...

The method works fine when i call it in DataItemBound method..

any idea?Hi,

Try using

int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))

DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com
Tod thank you so much :) it worked..

still confused why one of them works not the other as shown below:
<TD><%# bs.getCampusName((int)DataBinder.Eval(Container.Da taItem,
"CampusID"))%></TD
<td><%# bs.getCampusName((int.Parse(DataBinder.Eval(Contai ner.DataItem,
"Priority")))%></td
both CampusID and Priority is same type of value..

Many Thanks again.

"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Sorry that did not solve the problem... :( i am getting this error message
now:

The best overloaded method match for 'int.Parse(string)' has some invalid
arguments

"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Acutally, DataBinder.Eval returns an object unless you pass a third
parameter, a format specifier, i.e.

DataBinder.Eval(Container.DataItem, "Priority", "{0:d}")

Otherwise you get an object reference back, in which case you could
use Convert.ToInt32

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 9 Nov 2004 07:38:03 -0800, "huzz"
<huzz@.discussions.microsoft.com> wrote:

>Sorry that did not solve the problem... :( i am getting this error message
>now:
>The best overloaded method match for 'int.Parse(string)' has some invalid
>arguments
>"Tod Birdsall" wrote:
>> Hi,
>>
>> Try using
>>
>> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
>>
>> DataBinder.Eval returns a string value type. (int) is used to
>> implicitly cast values to integers. Strings must be explicitly cast
>> using the Parse method.
>> Hope this helps.
>>
>> Tod Birdsall, MCP
>> http://tod1d.blogspot.com
>>
>
Hi,

Scott is correct. Sorry for the mis-information.

I tried to reproduce your error message. I created a function in the
code behind like so:

protected string GetRemainderInEscrow(decimal approvedAmount, object
paidAmount)

I then called the method from the aspx page using the following code :

<%# GetRemainderInEscrow( (decimal)DataBinder.Eval(Container,
"DataItem.ApprovedAmount"), DataBinder.Eval(Container, "DataItem.Paid")
) %
The code worked as it should. If you have control over the
'bs.getPriority' method, try allowing an object to be passed instead of
an integer value type. If that doesn't work. If that still does not
work, copy and paste the exact error message and Stack Trace.
Tod Birdsall, MCP
http://tod1d.blogspot.com