neI have a DropDownList with a list of value.
I need in my code USE the value selected by the User in the DropDownList AS INT DataType (numeric).
At the moment I am using this code below (CONVERTING DATATYOES).
Script work just fine.
But I would like to know if exists an alternative way to do it.
Any ideas it is very appreciate. Thanks for your time.
<asp:DropDownList ID="uxPageSizeUsersSelector" runat="server"
AutoPostBack="True"
onselectedindexchanged="uxPageSizeUsersSelector_SelectedIndexChanged">
<asp:ListItem Value="1" Selected="True">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:DropDownList>
int myPageSize = Convert.ToInt16(uxPageSizeUsersSelector.SelectedValue.ToString());
PageSize = myPageSize;
You can use the try parse method. This will make sure that your value is an int, and if not, allow you to handle the problem instead of throwing an exception:
You can do it for Int16 DateTime etc. too.