data binding - asp.net Dropdown list databinding in runtime -
con = new sqlconnection(s); con.open(); if (radiobuttonlist1.selectedindex == 0) { cmd = new sqlcommand("select [item] veg_items", con); da = new sqldataadapter(cmd); dataset ds = new dataset(); da.fill(ds, "[item]"); dropdownlist1.datasource = ds.tables[0]; dropdownlist1.databind(); } else if (radiobuttonlist1.selectedindex == 1) { cmd = new sqlcommand("select [item] nonveg_items", con); da = new sqldataadapter(cmd); dataset ds = new dataset(); da.fill(ds, "[item]"); dropdownlist1.datasource = ds.tables[0]; dropdownlist1.databind(); } con.close(); }
i have items in table , need items displayed in dropdownlist
once select value in radiobuttonlist
. visualized items in ds.tables[0]
line can't bind them dropdownlist
.
con.open(); if (radiobuttonlist1.selectedindex == 0) { cmd = new sqlcommand("select [item] [veg_items]", con); sqldatareader dr = cmd.executereader(); list<object> lt = new list<object>(); if (dr.hasrows) { while (dr.read()) { lt.add(dr["item"].tostring()); } } dropdownlist1.datasource = lt; dropdownlist1.databind(); } else if (radiobuttonlist1.selectedindex == 1) { cmd = new sqlcommand("select [item] [nonveg_items]", con); sqldatareader dr = cmd.executereader(); list<object> lt = new list<object>(); if (dr.hasrows) { while (dr.read()) { lt.add(dr["item"].tostring()); } } dropdownlist1.datasource = lt; dropdownlist1.databind(); } con.close();
Comments
Post a Comment