con il Parse
codice:
public bool IsNumeric(String s)
{
// provo a cambiarlo in double e vedo
// se genere un exception
try
{
Double.Parse(s);
}
catch
{
// se la crea restituisce false
return false;
}
// altrimenti tutto ok
return true;
}
ESEMPIO
String s = "";
String s2 = "20";
if (IsNumeric(s))Response.write("NUMERO");
else Response.write("STRINGA" + "
")
if (IsNumeric(s2))Response.write("NUMERO");
else Response.write("STRINGA")
'Output
STRINGA
NUMERO
se il numero sei sicura che non sia decimale puoi anche restringere ed usare Int32 invece di Double