Csharp: asp.net CheckBoxList databind

Source: Internet
Author: User

/// <Summary> /// CheckBoxList data source // aggregation // 20130705 //// </summary> private void setCheckBoxList () {DataTable dt = new DataTable (); CheckBoxList1.Items. clear (); dt = geovindu_branchBLL.SelectGeovindu_branchNameDt (); CheckBoxList1.DataSource = dt; this. checkBoxList1.DataTextField = "B _Name"; this. checkBoxList1.DataValueField = "B _EnglishName"; CheckBoxList1.DataBind ();} // <summary> ////// </Summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> protected void Page_Load (object sender, eventArgs e) {if (! IsPostBack) {setCheckBoxList ();}} /// <summary> /// specify the target category of the selected region. /// </summary> /// <param name = "sender"> </param> // /<param name = "e"> </param> protected void button#click (object sender, eventArgs e) {string variable = string. empty; int I = 0; foreach (System. web. UI. webControls. listItem oItem in CheckBoxList1.Items) {if (oItem. selected) // if you want only selected {if (I = 0) {variable = oItem. value;} else {variable = variable + "," + oItem. value;} I ++;} // otherwise get for all items // variable = oItem. value;} // returns the Value of this to the parent plane. page. controls. add (new LiteralControl (string. format ("<script> opener.document.form1.txt ShoppingDealsBranch. value = '{0}' </script> ", variable); // close this window. page. controls. add (new LiteralControl ("<script> window. close (); </script> "));
<Asp: checkBoxList ID = "CheckBoxList1" runat = "server" RepeatDirection = "Horizontal" comment = "True" DataTextField = "B _Name" DataValueField = "B _EnglishName" RepeatColumns = "6" CellPadding = "5 "CellSpacing =" 5 "RepeatLayout =" Table "BorderStyle =" Outset "CssClass =" geovindu "> </asp: checkBoxList> <br/> <asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "Confirm"/> </div>

 

<style type="text/css">  .geovindu INPUT{ color:black; border-style: none; font-family: Tahoma; font-size: 7px; margin-right: 5px}.geovindu td {     /*  font-size:x-large;*/    width:300px;   }    </style>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.