国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

BS常用方法備忘

2019-11-17 01:47:18
字體:
來源:轉載
供稿:網友
BS常用方法備忘

在B/S項目開發過程中總結的一些常用方法,如:常量、驗證方法、服務器控件方法、html控件方法等。

  1 ///******************* 說明 ***************************///  2 ///     作者:清風攜夕陽  3 ///     時間:2014-09-29  4 ///     描述:Web服務端控件輔助類,程序開發過程中常用方法  5 ///***************************************************///  6 using System;  7 using System.Data;  8 using System.Collections.Generic;  9 using System.Web.UI.WebControls; 10 namespace Common 11 { 12     /// <summary> 13     /// Web服務端控件輔助類 14     /// </summary> 15     [Serializable] 16     public static class WebHelper 17     { 18         #region 常量、靜態變量 19         /// <summary> 20         /// 8位時間格式yyyymmdd 21         /// </summary> 22         public static string time8 = "yyyymmdd"; 23         /// <summary> 24         /// 10位時間格式yyyy-mm-dd 25         /// </summary> 26         public static string time10 = "yyyy-mm-dd"; 27         /// <summary> 28         /// 通用空值選項文本 29         /// </summary> 30         public static string emptySelect = "--請選擇--"; 31         #endregion 32         #region 驗證、檢測方法 33          /// <summary> 34          /// 驗證sql匹配條件是否正確(若以and開頭則自動去除) 35          /// </summary> 36          /// <param name="strWhere">sql匹配條件</param> 37         public static string CheckStrWhere(string strWhere) 38         { 39             string str = strWhere.TrimStart();//去除前置空格 40             if (str.ToLower().IndexOf("and ") == 0)//若以and開頭則自動去除第一個and 41             { 42                 strWhere = str.Substring(4);//若要保留前面一個空格,可以改為3 43             } 44             return strWhere; 45         } 46         #endregion 47         #region 服務端控件方法 48  49         #region CheckBoxList 50         /// <summary> 51         /// 獲取CheckBoxList選中項數目 52         /// </summary> 53         public static int CheckedCount(CheckBoxList ckboxlist) 54         { 55             int count = 0; 56             foreach (ListItem item in ckboxlist.Items) 57             { 58                 if (item.Selected == true) 59                 { 60                     count++; 61                 } 62             } 63             return count; 64         } 65         /// <summary> 66         /// 根據選項值選中CheckBoxList選項 67         /// </summary> 68         public static void SetChecked(CheckBoxList cboxlist, List<string> vals) 69         { 70             if (vals == null || vals.Count == 0) 71             { 72                 return; 73             } 74             for (int i = 0; i < cboxlist.Items.Count; i++) 75             { 76                 ListItem item = cboxlist.Items[i]; 77                 for (int j = 0; j < vals.Count; j++) 78                 { 79                     if (item.Value == vals[j]) 80                     { 81                         item.Selected = true; 82                         vals.Remove(vals[j]); 83                         break; 84                     } 85                 } 86                 if (vals.Count == 0) 87                 { 88                     return; 89                 } 90             } 91         } 92         /// <summary> 93         /// 獲取CheckBoxList選中項的值 94         /// </summary> 95         public static List<string> GetChecked(CheckBoxList cboxlist) 96         { 97             List<string> vals = new List<string>(); 98             foreach (ListItem item in cboxlist.Items) 99             {100                 if (item.Selected == true)101                 {102                     vals.Add(item.Value);103                 }104             }105             return vals;106         }107         /// <summary>108         /// 清空選項109         /// </summary>110         public static void ClearChecked(CheckBoxList cboxlist)111         {112             foreach (ListItem item in cboxlist.Items)113             {114                 item.Selected = false;115             }116         }117         /// <summary>118         /// 全選119         /// </summary>120         public static void CheckAll(CheckBoxList cboxlist)121         {122             foreach (ListItem item in cboxlist.Items)123             {124                 item.Selected = true;125             }126         }127         /// <summary>128         /// 反選129         /// </summary>130         public static void CheckNotChecked(CheckBoxList cboxlist)131         {132             foreach (ListItem item in cboxlist.Items)133             {134                 item.Selected = !item.Selected;135             }136         }137         /// <summary>138         /// 根據數據表綁定CheckBoxList控件139         /// </summary>140         /// <param name="dt">數據表</param>141         /// <param name="TextField">選項名稱列編碼</param>142         /// <param name="ValueField">選項值列編碼</param>143         public static void BindCheckBoxList(CheckBoxList cboxlist, DataTable dt, string TextField, string ValueField)144         {145             cboxlist.Items.Clear();146             if (dt != null && dt.Rows.Count > 0)147             {148                 cboxlist.DataSource = dt;149                 cboxlist.DataTextField = TextField;150                 cboxlist.DataValueField = ValueField;151                 cboxlist.DataBind();152             }153         }154         #endregion155         #region RadioButtonList156         /// <summary>157         /// 根據數據表綁定RadioButtonList控件158         /// </summary>159         /// <param name="dt">數據</param>160         /// <param name="TextField">選項名稱列編碼</param>161         /// <param name="ValueField">選項值列編碼</param>162         public static void BindRadioButtonList(RadioButtonList rdolist, DataTable dt, string TextField, string ValueField)163         {164             rdolist.Items.Clear();165             if (dt != null && dt.Rows.Count > 0)166             {167                 rdolist.DataSource = dt;168                 rdolist.DataTextField = TextField;169                 rdolist.DataValueField = ValueField;170                 rdolist.DataBind();171             }172         }173         #endregion174         #region DropDownList175         /// <summary>176         /// 根據數據表綁定RadioButtonList控件177         /// </summary>178         /// <param name="dt">數據表</param>179         /// <param name="TextField">選項名稱列編碼</param>180         /// <param name="ValueField">選項值列編碼</param>181         /// <param name="ListName">空值顯示文本,若為空則無空值選項</param>182         public static void BindDropDownList(DropDownList dlist, DataTable dt, string TextField, string ValueField, string EmptyValueText)183         {184             dlist.Items.Clear();185             if (dt != null && dt.Rows.Count > 0)186             {187                 dlist.DataSource = dt;188                 dlist.DataTextField = TextField;189                 dlist.DataValueField = ValueField;190                 dlist.DataBind();191             }192             if (!String.IsNullOrEmpty(EmptyValueText))193             {194                 dlist.Items.Insert(0, new ListItem(EmptyValueText, ""));195             }196         }197         #endregion198         #region ListBox199         /// <summary>200         /// 根據數據表綁定ListBox控件201         /// </summary>202         /// <param name="dt">數據表</param>203         /// <param name="TextField">選項名稱列編碼</param>204         /// <param name="ValueField">選項值列編碼</param>205         public static void BindListBox(ListBox lbox, DataTable dt, string TextField, string ValueField)206         {207             lbox.Items.Clear();208             if (dt != null && dt.Rows.Count > 0)209             {210                 lbox.DataSo
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广饶县| 长泰县| 香港| 云霄县| 北碚区| 界首市| 清镇市| 丰顺县| 陇川县| 定结县| 临桂县| 天柱县| 洪江市| 章丘市| 恭城| 平昌县| 越西县| 共和县| 肥城市| 墨江| 芦山县| 张北县| 板桥市| 同德县| 阳朔县| 九龙坡区| 阿瓦提县| 炎陵县| 天全县| 资源县| 周至县| 万安县| 珲春市| 锡林郭勒盟| 儋州市| 霍城县| 衢州市| 平度市| 辽源市| 桦南县| 牟定县|