Input string was not in a correct format [closed]
I am getting the following error on below code.
Input string was not in a correct format.
Code:
private void RefreshListType(bool forExport)
{
grdListItems.DataSource = ListType.GetListTypes(Convert.ToInt16(cboListType.SelectedValue));
grdListItems.DataBind();
lblCount.InnerText = "LookUps: " + grdListItems.Rows.Count.ToString();
}
Please help me.
Likely cboListType.SelectedValue
is not able to be made into an int16
.
You can use int16.TryParse
.
SelectedValue doesn't return a number?
You could put a TryParse in before to check that the selected item has a numeric value.
Int16 nValue = -1;
if (Int16.TryParse(cboListType.SelectedValue, out nValue))
{
// Proceed
}
The value you are getting from cboListType.SelectedValue
is not convertible to Int16.
Right-click on the page and select "View Source" and then hit Control-F to search for "cboListType" look at the value that is selected.
You can also use Response.Write
or a javascript alert to write the value.
This, most likely, means that cboListType.SelectedValue
is not a valid number
精彩评论