/// <summary> /// 获取控件 Int 参数值,ctrl 必须是文本控件 /// </summary> /// <param name="ctrl"></param> /// <param name="defValue"></param> /// <returns></returns> public static int GetInt(Control ctrl, int defValue) { if (ctrl == null) { throw new ArgumentNullException("获取文本内容的控件不能为空!"); } if (ctrl is ITextControl) { return(TypeParse.StrToInt(GetText(ctrl as ITextControl), defValue)); } if (ctrl is HtmlInputControl) { return(TypeParse.StrToInt(GetText(ctrl as HtmlInputControl), defValue)); } if (ctrl is HiddenField) { return(TypeParse.StrToInt(GetText(ctrl as HiddenField), defValue)); } return(defValue); }
/// <summary> /// 获取下拉列表值 /// </summary> /// <param name="ddlList"></param> /// <param name="defValue"></param> /// <returns></returns> public static byte GetSelectValue(DropDownList ddlList, byte defValue) { return((byte)TypeParse.StrToInt(GetSelectValue(ddlList), defValue)); }
/// <summary> /// 获取 Get 请求传递的int参数值 /// </summary> /// <param name="request">请求对象</param> /// <param name="strName">参数名称</param> /// <param name="defValue">设置参数的默认值,供返回使用</param> /// <returns>返回转换后的int参数值</returns> public static int GetQueryInt(HttpRequest request, string strName, int defValue) { return(TypeParse.StrToInt(request.QueryString[strName], defValue)); }
public static int StrToInt(string expression, int defValue) { return(TypeParse.StrToInt(expression, defValue)); }