.net - Ranking Priority using DropDownList in C# -
my idea build ranking priority using dropdownlist asp server control.
here's setup: have 3 dropdownlists , has 3 items ("first", "second", "third") on each dropdownlists. when have chosen 1st dropdownlist assuming item have selected "first" , on 2nd dropdownlist default selecteditem "first" item of 1st dropdownlist on have selected must swapped on 2nd dropdownlist.
in short there unique selecteditems on each dropdownlist , in every selectedindexchanged event occuring there swapping of items on 3 dropdownlists. that's ranking priority be.
my question be, how can swapped previous item on dropdownlist going 1 dropdownlist have selected on , placed new item?
here's code:
protected void dropdownlistpriority_selectedindexchanged(object sender, eventargs e) { dropdownlist ddlrank = (dropdownlist)sender; int swapindex; string sameddlselecteditemid; //get list of ddls list<dropdownlist> ddlranklist = new list<dropdownlist>(); ddlranklist.add(ddlbiometricnoorder); ddlranklist.add(ddldatetimeorder); ddlranklist.add(ddltransactiontypeorder); //store listitems ddl list<string> strranklist = new list<string>(); strranklist.add("first"); strranklist.add("second"); strranklist.add("third"); //holds temp. ddl list<dropdownlist> tempranklist = new list<dropdownlist>(); //remove '<-- select -->' item when ddl changed if(ddlrank.items.contains(new listitem("<-- select -->"))) ddlrank.items.removeat(0); //loop on each list<t> for(int x = 0; x < ddlranklist.count; x++) { (int y = 0; y < ddlranklist.elementat(x).items.count; y++) { if (ddlranklist.elementat(x).items[y].text != ddlrank.selecteditem.text) { //check amongst unselected item changed (int swapindex) swapindex = convert.toint32(ddlranklist.elementat(x).items[y].value); } } } foreach (dropdownlist ddl in ddlranklist) { foreach (string strrank in strranklist) { if (ddlrank.selecteditem.text == ddl.selecteditem.text) { sameddlselecteditemid = ddl.id; //set ddl selectedindex ddl.selectedindex = //this question; } } } }
i see have considered approach lists repopulated @ server end. there specific reason server postbacks costly. instead why don't consider jquery/javascript based solution lists manipulated based on user selected values.
you can implement event based model well. refer this
Comments
Post a Comment