PS:最近在做權(quán)限管理這個(gè)模塊,發(fā)現(xiàn)用checkbox的地方挺多的,于是寫了個(gè)簡單的例子,以供以后學(xué)習(xí)和使用。
1.前端頁面:
<form id="form1" method="get" runat="server"> <input name="chk_per" type="checkbox" value="3" />張三 <input name="chk_per" type="checkbox" value="4" />李四 <input name="chk_per" type="checkbox" value="5" />王五 <input name="chk_per" type="checkbox" value="6" />趙六 <input name="chk_per" type="checkbox" value="7" />孫琦 <input name="chk_per" type="checkbox" value="8" />豬八 <input type="submit" id="btnOK" value="提交" /> </form>
2.后臺(tái)方法:
#region 獲取從前端頁面回傳過來的 CheckBox 的值 void GetCheckBoxValue() /// <summary> /// 獲取從前端頁面回傳過來的 CheckBox 的值 /// <para>Request.Form["chk_per"] 以逗號(hào)分割,獲取所有選中的 CheckBox 的值</para> /// </summary> private void GetCheckBoxValue() { string user = Request["chk_per"]; string[] users = user.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); string s = string.Empty; foreach (var item in users) { s += item + " | "; } } #endregion
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { //測試調(diào)用 GetCheckBoxValue(); }}
新聞熱點(diǎn)
疑難解答
圖片精選