c# - listbox selectedindex only selecting last element -


i have listbox bound list of objects database. have secondary list has less objects want use mark selected elements.

        cell = new htmltablecell();         list<clasaautor> listaautori = datatabletoclasaautor(dal.citestetotiautori());         list<clasaautor> listaautoripublicatie = datatabletoclasaautor(dal.citestetotiautoriuneipublicatii(guidpublicatie));         listbox list = new listbox();         list.selectionmode = listselectionmode.multiple;         list.id = "cbautori";         list.datasource = listaautori;         list.datatextfield = "numecomplet";         list.datavaluefield = "guidautor";         list.databind();         foreach (clasaautor autor in listaautoripublicatie)         {             (int = 0; < list.items.count; i++)             {                 if (list.items[i].value == autor.guidautor.tostring())                     list.selectedindex = i;             }         }          cell.controls.add(list);         row.cells.add(cell); 

the problem last element gets selected... why? how can fix it?

my if ok, gets true 2 times...

try loop:

foreach (clasaautor autor in listaautoripublicatie) {     foreach (listitem item in list.items)     {         if (item.value == autor.guidautor.tostring())             item.selected = true;     } } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -