views:

38

answers:

2

How to get asp.net return drop down list to return value as int

I want to pass the value to a stored procedure as an integer. But the default appears to be as a string which is not what the store procedure is expecting.

Is there a good way to return the list values as ints?

I suspect I can you set the value on the change selection event, is there another way?

A: 

You can call int.Parse(value).

SLaks
+1  A: 
DropDownList d = Your_Drop_Down_List;

int i;

if(int.TryParse(d.SelectedValue, out i))
{
  do stuff with i here.
}
else
{
  //selected value did not parse.
}
Kevin