c# - How to bind ComboBox from ArrayList Values in asp.net? -


enter image description here

but not fill properly

i have mention such table , code image

code :

        datatable dtusertype = new common().getusertype(true);         datatable dtusertype 1= new common().getusertypebyuser(true);          arraylist lstusertypeid =new arraylist();         lstusertypeid.addrange(dtusertype1.rows[0]["usertypeid"].tostring().split(','));          datatable dtdownlist = new datatable();         dtdownlist.columns.add("usertypeid");         dtdownlist.columns.add("usertype");         datarow dr;           foreach (string s in lstusertypeid)         {             (int = 0; < dtusertype.rows.count; i++)             {                  dr = dtdownlist.newrow();                  //list of superior list                 if(s.tostring() != dtusertype.rows[i]["usertypeid"].tostring())                 {                       dr["usertype"] = dtusertype.rows[i]["usertype"].tostring();                     dr["usertypeid"] = dtusertype.rows[i]["usertypeid"].tostring();                     dtdownlist.rows.add(dr);                 }               }         }           cmbuser.datasource = dtdownlist;          cmbuser.datatextfield = "usertype";         cmbuser.datavaluefield = "usertypeid";         cmbuser.databind(); 

in general:

  1. don't split main table sub tables 1 column each - why there columns in table
  2. when querying data - use linq
  3. dont use datatable when possible - observer how many casting operations posted in answer (in case use typed table common)

    datatable common = new common(); // id, usertype, usertypeid  var sections = common.where(c => c.usertype.tostring() == "b").first()                      .tostring().split(',');  datatable dtdownlist = new datatable(); dtdownlist.columns.add("usertypeid"); dtdownlist.columns.add("usertype"); datarow dr;   foreach (string id in sections) {     (int = 0; < dtusertype.rows.count; i++)     {         if(convert.toint16(id) == convert.toint16(common.rows[i]["id"]))         {             dr = dtdownlist.newrow();              dr["usertype"] = dtusertype.rows[i]["usertype"].tostring();             dr["usertypeid"] = dtusertype.rows[i]["usertypeid"].tostring();             dtdownlist.rows.add(dr);         }     } }   cmbuser.datasource = dtdownlist;  cmbuser.datatextfield = "usertype"; cmbuser.datavaluefield = "usertypeid"; cmbuser.databind(); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -