2.總結CheckBoxList js

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