// 底下這一段IF判別式,是用來防呆,防止一些例外狀況。-- start --
if (Request["p"] == null)
{
p = 1;
}
else
{
if (IsNumeric(Request["p"]))
{
//有任何問題,就強制跳回第一頁(p=1)。
//頁數(p)務必是一個整數。而且需要大於零、比起「資料的總頁數」要少
if ((p != null) & (p > 0) & (p <= Pages))
{
p = Convert.ToInt32(Request["p"]);
}
else
{
p = 1;
}
}
else
{
p = 1;
}
} //上面這一段IF辦別式,是用來防呆,防止一些例外狀況。-- end --
// IsNumeric Function,檢查是否為整數型態? return true or false
// 資料來源:http://support.microsoft.com/kb/329488/zh-tw
static bool IsNumeric(object Expression)
{
// Variable to collect the Return value of the TryParse method.
bool isNum;
// Define variable to collect out parameter of the TryParse method. If the conversion fails, the out parameter is zero.
double retNum;
// The TryParse method converts a string in a specified style and culture-specific format to its double-precision floating point number equivalent.
// The TryParse method does not generate an exception if the conversion fails. If the conversion passes, True is returned. If it does not, False is returned.
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
return isNum;
}
留言列表