Use arrays as the checkboxlist Data Source

Source: Internet
Author: User

 

 Public Partial Class User_expectations: system. Web. UI. Page {guid _ rubricid; guid _ courseid; guid _ gradeid; String _ STR; Protected   Void Page_load ( Object Sender, eventargs e) {_ rubricid = New GUID (request. querystring [ "Rubric_id" ]. Tostring (); rubric. BLL. rubrics mybll = New Rubric. BLL. rubrics (); _ courseid = New GUID (mybll. GetModel (_ rubricid). courseid. tostring (); _ gradeid = New GUID (mybll. GetModel (_ rubricid). gradeid. tostring ()); If (! Page. ispostback) {checkboxlist1bind (); checkboxlist2bind ();}} Protected   Void Rbl_selectedindexchanged ( Object Sender, eventargs e) {}# region datalist binding method // Private void dldescription1bind ()      //{      // Rubric. BLL. Expectations mybll = new rubric. BLL. Expectations ();      // If (RBL. items [0]. Selected)     //{      // _ STR = "courseid = '" + _ courseid + "' and isspecific = 0 ";      // Dataset DS = mybll. getlist (_ Str );      // Dldescription1.datasource = Ds;      // Dldescription1.databind ();      //}      // Else      //{      // _ STR = "gradeid = '" + _ gradeid + "' and isspecific = 0 ";      // Dataset DS = mybll. getlist (_ Str );      // Dldescription1.datasource = Ds;      // Dldescription1.databind ();     //}      //} # Endregion # region checkboxlist1 Data Binding Private   Void Checkboxlist1bind () {rubric. BLL. Expectations mybll = New Rubric. BLL. Expectations (); If (RBL. items [0]. Selected) {_ STR = "Courseid = '" + _ Courseid + "'And isspecpacific = 0" ; Dataset DS = mybll. getlist (_ Str); checkboxlist1.datasource = Ds; checkboxlist1.datatextfield = "Description" ; Checkboxlist1.datavaluefield ="Expecid" ; Checkboxlist1.databind ();} Else {_ STR = "Gradeid = '" + _ Gradeid + "'And isspecpacific = 0" ; Dataset DS = mybll. getlist (_ Str); checkboxlist1.datasource = Ds; checkboxlist1.datatextfield = "Description" ; Checkboxlist1.datavaluefield = "Expecid" ; Checkboxlist1.databind () ;}# endregion # region checkboxlist2 Data Binding Private   Void Checkboxlist2bind () {rubric. BLL. Expectations mybll =New Rubric. BLL. Expectations (); If (RBL. items [0]. Selected) {_ STR = "Courseid = '" + _ Courseid + "'And isspecpacific = 1" ; Dataset DS = mybll. getlist (_ Str); checkboxlist2.datasource = Ds; checkboxlist2.datatextfield = "Description" ; Checkboxlist2.datavaluefield = "Expecid" ; Checkboxlist2.databind ();} Else {_ STR = "Gradeid = '" + _ Gradeid +"'And isspecpacific = 1" ; Dataset DS = mybll. getlist (_ Str); checkboxlist2.datasource = Ds; checkboxlist2.datatextfield = "Description" ; Checkboxlist2.datavaluefield = "Expecid" ; Checkboxlist2.databind () ;}# endregion # region datalist Data Binding // Private void dldescription2bind ()      //{      // Rubric. BLL. Expectations mybll = new rubric. BLL. Expectations ();      // If (RBL. items [0]. Selected)      //{      // _ STR = "courseid = '" + _ courseid + "' and isspecific = 1 ";     // Dataset DS = mybll. getlist (_ Str );      // Dldescription2.datasource = Ds;      // Dldescription2.databind ();      //}      // Else      //{      // _ STR = "gradeid = '" + _ gradeid + "' and isspecific = 1 ";      // Dataset DS = mybll. getlist (_ Str );      // Dldescription2.datasource = Ds;      // Dldescription2.databind ();      //}      //} # Endregion # used for Region Testing//// Add selected item 1      // Protected void btnaddmediaclick (Object sender, eventargs E)      //{      // # Region is useless     /// For (INT I = 0; I ////{      /// If (dldescription1.items [I]. itemtype = listitemtype. selecteditem)      ////{      /// Checkbox chk = (checkbox) dldescription1.items [I]. findcontrol ("chkitem ");      //// If (chk. Checked)      ////{      //// Guid _ expecid = new GUID (dldescription1.datakeys [I]. tostring ());     ///// Rubric. BLL. Expectations mybll = new rubric. BLL. Expectations ();      //// Dataset DS = mybll. getlist ("expecid = '" + _ expecid + "'");      ///// Dlselected1.datasource = Ds;      ///// Dlselected1.databind ();      //// Response. Write (chk. Text );      ////}      ////}      ////}      // # Endregion      // Foreach (datalistitem myitem in dldescription1.items)      //{     // Checkbox chk = (checkbox) myitem. findcontrol ("chkitem ");      // If (chk. Checked)      //{      // Guid _ expecid = new GUID (dldescription1.datakeys [myitem. itemindex]. tostring ());      // Rubric. BLL. Expectations mybll = new rubric. BLL. Expectations ();      // Dataset DS = mybll. getlist ("expecid = '" + _ expecid + "'");      // Dlselected1.datasource = Ds;      // Response. Write (chk. Text );      //}      //}      // Dlselected1.databind ();     //} # Endregion ///      /// Add the expected left to the right      /// # Region add the left to the right // Protected void button#click (Object sender, eventargs E)      //{     /// For (INT I = 0; I ////{      /// If (checkboxlist1.items [I]. Selected)      ////{      /// Response. Write (checkboxlist1.items [I]. Text. tostring ());      /// Guid _ expecid = new GUID (checkboxlist1.items [I]. value. tostring ());     /// Rubric. BLL. Expectations mybll = new rubric. BLL. Expectations ();      //// Listitem item = new listitem ();      /// Item. Text = mybll. GetModel (_ expecid). description. tostring ();;      /// Item. value = mybll. GetModel (_ expecid). expecid. tostring ();      //// Checkboxlist2.items. Add (item );      //// Checkboxlist1.items. Remove (item );      ////}      ////}      //} # Endregion Protected   Void Btnaddmediaclick (Object Sender, eventargs e ){ Int _ COUNT = Int . Parse (checkboxlist1.items. Count. tostring ()); String [] Arr = New   String [_ Count]; For ( Int I = 0; I if(Checkboxlist1.items [I]. Selected) {guid _ expecid = New GUID (checkboxlist1.items [I]. value. tostring (); rubric. BLL. Expectations mybll = New Rubric. BLL. Expectations (); arr [I] = mybll. GetModel (_ expecid). description. tostring (); checkboxlist1.items [I]. Selected = False ; Checkboxlist12.datavaluefield = mybll. GetModel (_ expecid). expecid. tostring (); checkboxlist12.items. Add (ARR [I]. tostring ()); // Checkboxlist1.items. removeat (I); // remove the listitem of the specified index from the set                // Checkboxlist1.databind ();                // Checkboxlist12.databind (); } # Region test Code          // Foreach (listitem item in checkboxlist1.items)          //{          // If (item. Selected)         //{          // Guid _ expecid = new GUID (item. value. tostring ());          // Rubric. BLL. Expectations mybll = new rubric. BLL. Expectations ();          // Item. Text = mybll. GetModel (_ expecid). description. tostring ();;          // Item. value = mybll. GetModel (_ expecid). expecid. tostring ();          // Checkboxlist2.items. Add (item );          // Checkboxlist1.items. Remove (item );          //}          //} # Endregion} // Add special expectation to the right      Protected  Void Btnadd2_click ( Object Sender, eventargs e ){ Int _ COUNT = Int . Parse (checkboxlist2.items. Count. tostring ()); String [] Arr = New   String [_ Count]; For ( Int I = 0; I if(Checkboxlist2.items [I]. Selected) {guid _ expecid = New GUID (checkboxlist2.items [I]. value. tostring (); rubric. BLL. Expectations mybll =New Rubric. BLL. Expectations (); arr [I] = mybll. GetModel (_ expecid). description. tostring (); checkboxlist2.items [I]. Selected = False ; Checkboxlist22.datavaluefield = mybll. GetModel (_ expecid). expecid. tostring (); checkboxlist22.items. Add (ARR [I]. tostring ()); // Checkboxlist2.items. removeat (I); // remove the listitem of the specified index from the set }}} // Remove the selected general expectation to the left      Protected   Void Btnremoveappsclick ( Object Sender, eventargs e ){ Try {For ( Int I = 0; I if (checkboxlist12.items [I]. Selected) {checkboxlist12.items. removeat (I); checkboxlist12.databind ();}}} Catch {}} // Remove the selected special expectation to the left      Protected   Void Btnremove2_click ( Object Sender, eventargs e ){ Try { For ( Int I = 0; I if (checkboxlist22.items [I]. Selected) {checkboxlist22.items. removeat (I); checkboxlist22.databind ();}}} Catch {}} // Remove all selected general expectations      Protected   Void Btnremoveall1_click ( Object Sender, eventargs e) {checkboxlist12.items. Clear ();} // Remove all selected special expectations      Protected   Void Btnremoveall2_click ( Object Sender, eventargs e) {checkboxlist22.items. Clear ();} //      Protected   Void Btnadd_click ( Object Sender, eventargs e ){}}

 

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.