Invalid Cast

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I run the following code:

private string GetSystemPriorityRange()
{
decimal fromPriority = Convert.ToDecimal(systemPriorityFromList.SelectedItem);
decimal toPriority = Convert.ToDecimal(systemPriorityToList.SelectedItem);
if (systemPriorityRangeCheck.Checked == true)
{
return " and wo6 between " + "'" + fromPriority + "'" + " and " + "'" + toPriority + "'";
}
else
{
return null;
}
}

I get the following error:

Specified cast is not valid.

The values involved are things like 0, 1.00, 1.60, 2.50

Aren't these decimal types. How should I alter my code to handle this?

Thanks,

Dave
 
I SelectedItem property will return the textual representation of the item (e.g. High Prioirity, Low Priority, etc) rather than the actual values themselves (1.0, 1.5). Try SelectedValue instead

Not
systemPriorityFromList.SelectedIte
systemPriorityToList.SelectedIte

Try this
systemPriorityFromList.SelectedValu
systemPriorityToList.SelectedValue
 
What is the return type of systemPriorityFromList.SelectedItem and systemPriorityToList.SelectedItem

If you switch out those values with an object with a value of 1.60 or a string with a value of "1.60", verything works just fine, so I'd say you're trying to convert to a deciaml from a type that's not supported.
 

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

Back
Top