Maestro1024
Maestro1024

Reputation: 3293

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

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?

Upvotes: 0

Views: 1443

Answers (2)

kemiller2002
kemiller2002

Reputation: 115508

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.
}

Upvotes: 1

SLaks
SLaks

Reputation: 887767

You can call int.Parse(value).

Upvotes: 0

Related Questions