Selecting the shortest item string from dropdownlist in C# Asp.net -


i have multiple dynamically generated dropdownlists bound database. want shortest string value shown @ index 0 in each dropdown.

the sample code is:

dropdownlist ddltemplate = new dropdownlist(); ddltemplate.id = "ddltemplate|" + j.tostring(); ddltemplate.appenddatabounditems = true; ddltemplate.datatextfield = "templatename"; ddltemplate.datavaluefield = "templatename"; ddltemplate.width = unit.pixel(200); ddltemplate.autopostback = true; ddltemplate.datasource = null; ddltemplate.datasource = dsmultipletemplate.tables[j].defaultview; ddltemplate.databind(); 

if can achieved through database query please guide me.

thanks

as arnt answering comment, maybe looking that:

    list<int> stringlength = new list<int> { }; // storing every length      foreach (string entry in ddltemplate.items)     {         stringlength.add(entry.length); // saving each string-length     }      int index = stringlength.findindex(a => == stringlength.min()); // index of lowst length     ddltemplate.selectedindex = index; // set selected value index above 

this way, item wouldnt @ index 0, selected. placing index 0 basic. guess can on own.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -