working with dropdownlist in asp.net c# -
i have 2 dropdownlist in asp.net c#, 1 has 2 items in it('ok' 'pk') , other 1 bound database field , has 158 items in it.
i want remove 2 items second list when user selects 'ok' , keep original list when user selects 'pk'.
how can it?? have bound second list database there property can hide values in list??
first, dropdownlists have remove option. like
ddl.items.remove(ddl.items.findbyvalue("value"));
another way not select items list. refers question "hide" database values after retrieving. take use dropdownlists below:
dropdownlist1.datasource =ds.tables[0]; // list of items retrieved db
if display subset of table retrieve records need database using whatever db connection options have. instance after user selected ok use pseudo code below:
// full list allitems = db.getallitems(); selecteditems = allitems.where(p => p.itemid != itemid1 || itemid2); dropdownlist1.datasource = selecteditems;
and rest specify rest of required values init dropdown.
or in other example code, like:
sqlcommand ddsqlcommand = new sqlcommand("select * tablename id <> id1 , id <> id2", ddsqlconnection); ddsqlconnection.open(); dddr = ddsqlcommand.executereader(commandbehavior.closeconnection); dropdownlist1.datasource = dddr;
Comments
Post a Comment