c# - My Checkboxlist does not show multiple data from database? -


i trying bind checkboxlist programatically based on 2 input variables ; 1 checkbox instead of 3 .

here codes

this business layer

 public class baldisplaypanel2 {      private string _mylabel;      public string mylabel     {         { return _mylabel;  }         set { _mylabel = value; }     }      private string _conditionlabel;      public string conditionlabel     {         { return _conditionlabel; }         set { _conditionlabel = value; }     }       private string _checkboxquestion;      public string checkboxquestion     {         { return _checkboxquestion; }         set { _checkboxquestion = value; }     } 

this data access layer

 public list<baldisplaypanel2> displayspanelq(int tbid, int grdid)     {          sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["mynewdbconnectionstring"].connectionstring);         conn.open();         sqlcommand cmd = new sqlcommand("esp_mycheckboxproc", conn);         cmd.commandtype = commandtype.storedprocedure;         list<baldisplaypanel2> lst = new list<baldisplaypanel2>();         cmd.parameters.addwithvalue("@emp", tbid);         cmd.parameters.addwithvalue("@unitnumber", grdid);          sqldatareader dr = cmd.executereader();          while (dr.read())         {             baldisplaypanel2 unt = new baldisplaypanel2();             unt.checkboxquestion = dr["checkquest"].tostring();             unt.mylabel = dr["mylabel"].tostring();             unt.conditionlabel = dr["conditionlabel"].tostring();              //unt.labels = dr["labelq2"].tostring();             lst.add(unt);         }          conn.close();         return lst;      } 

this default.cs file call checkbox

        baldisplaypanel2 bl = new baldisplaypanel2();         daldisplaypanel2 dal = new daldisplaypanel2();         list<baldisplaypanel2> lst = new list<baldisplaypanel2>();         lst = dal.displayspanelq(convert.toint32(tbempid.text), convert.toint32(gridview1.selectedrow.cells[2].text));          foreach (var item in lst)         {              chbklstpanel3.items.clear();             chbklstpanel3.datasource = lst;             chbklstpanel3.datatextfield = item.checkboxquestion;              lblpanel3.text = item.mylabel;             lblcondition.text = item.conditionlabel;               } 

any appriciate

actually doing there looping result , binding checklistbox inside it. here if have 3 records loop 3 times. mentioned clear() checkboxlist inside loop. when comes third time clear checkboxlist , bind last record. thats getting 1 record on checkbox list.

so remove foreach loop,

    baldisplaypanel2 bl = new baldisplaypanel2();     daldisplaypanel2 dal = new daldisplaypanel2();     list<baldisplaypanel2> lst = new list<baldisplaypanel2>();     lst = dal.displayspanelq(convert.toint32(tbempid.text), convert.toint32(gridview1.selectedrow.cells[2].text));           chbklstpanel3.items.clear();         chbklstpanel3.datasource = lst;         chbklstpanel3.datatextfield = item.checkboxquestion;         chbklstpanel3.databind(); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -