- 後臺cs文件
- 1 using System;
- 2 using System.Data;
- 3 using System.Configuration;
- 4 using System.Collections;
- 5 using System.Web;
- 6 using System.Web.Security;
- 7 using System.Web.UI;
- 8 using System.Web.UI.WebControls;
- 9 using System.Web.UI.WebControls.WebParts;
- 10 using System.Web.UI.HtmlControls;
- 11 using System.Data.SqlClient;
- 12
- 13 public partial class chkandrdo : System.Web.UI.Page
- 14 {
- 15 protected void Page_Load( object sender, EventArgs e)
- 16 {
- 17 //WebControl -> CheckBoxList
- 18 if (!Page.IsPostBack)
- 19 BindchkBox1();
- 20 //WebControl -> RadioButtonList
- 21 if (!Page.IsPostBack)
- 22 BindradButList();
- 23
- 24 //HTMLControl -> ServerControl -checkbox
- 25 if (!Page.IsPostBack)
- 26 BindServerCheckBox();
- 27
- 28 }
- 29
- 30
- 31 public void BindchkBox1()
- 32 {
- 33 ListItem li = new ListItem( "江蘇" , "JS" );
- 34 chkBox1.Items.Insert(0, li);
- 35 li = new ListItem( "上海" , "SH" );
- 36 chkBox1.Items.Insert(0, li);
- 37 }
- 38
- 39 protected void btnCheck_Click( object sender, EventArgs e)
- 40 {
- 41 for ( int i = 0; i < chkBox1.Items.Count; i++)
- 42 {
- 43 if (chkBox1.Items[i].Selected)
- 44 Response.Write(chkBox1.Items[i].Value);
- 45 }
- 46
- 47 for ( int i = 0; i < radButList.Items.Count; i++)
- 48 {
- 49 if (radButList.Items[i].Selected)
- 50 Response.Write(radButList.Items[i].Value);
- 51 }
- 52 }
- 53
- 54
- 55 protected void BindradButList()
- 56 {
- 57 ListItem li = new ListItem( "南通" , "NT" );
- 58 radButList.Items.Insert(0, li);
- 59 li = new ListItem( "蘇州" , "SZ" );
- 60 radButList.Items.Insert(0, li);
- 61 }
- 62
- 63 protected void BindServerCheckBox()
- 64 {
- 65 chkBox2.Attributes.Add( "Region" , "Provience" );
- 66 chkBox2.Attributes.Add( "onclick" , "changeidd('ddd');" ); //這裏我爲chkBox2註冊了一個事件
- 67 chkBox3.Value = "SH" ;
- 68 chkBox3.Attributes.Add( "Region" , "Provience" );
- 69
- 70 radButList2.Value = "海闊" ;
- 71 Response.Write(radButList2.TagName); //得到input
- 72 radButList3.Value = "天空" ;
- 73 chkBox2.Name = "RadioButtonListArr" ; //這裏明明可以設置name 屬性,但是卻沒有什麼作用,不知道爲什麼???
- 74 chkBox3.Name = "RadioButtonListArr" ;
- 75 }
- 76
- 77 protected void btnCheck2_ServerClick( object sender, EventArgs e)
- 78 {
- 79 Response.Write(chkBox2.Value); //但是如果我想得到所有選中的由HTML轉化過來的服務器控件的值,我該怎麼辦呢??
- 80 Response.Write(Request.Form[ "radButList2Name" ]);
- 81 }
- 82 }
2.總結CheckBoxList js
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.