asp.net - How to select a value of a DropDownList that has been returned from a database -


i have web update form every control property of same table. should work way: whenever select value main(the first) dropdownlist, query should run getting of fields(properties) , filling other controls depending of value selected.

event code:

protected sub dropdownlist1_selectedindexchanged(byval sender object, byval e eventargs) handles dropdownlist1.selectedindexchanged         dim objmodel new modeldao ' data access class taht contains search method                   dim myobject = objmodel.searchobject(dropdownlist1.text)                               textbox1.text = myobject.property2         dropdownlist2.selectedvalue = myobject.property3 'what's wrong here?     end sub 

controls:

<asp:dropdownlist id="dropdownlist1" runat="server" appenddatabounditems="true"                     datasourceid="sqldatasource1" datatextfield="model" datavaluefield="model"                     autopostback="true" onselectedindexchanged="dropdownlist1_selectedindexchanged">                     <asp:listitem text="-select-" value="" />                     </asp:dropdownlist> <asp:dropdownlist id="dropdownlist2" runat="server">                         <asp:listitem value="0">-select-</asp:listitem>                         <asp:listitem>eds</asp:listitem>                         <asp:listitem>bds</asp:listitem>                                                 </asp:dropdownlist> 

it works except second dropdownlist, don't know how change selected value, tried this:

dropdownlist2.text = myobject.property3 

and this:

dropdownlist2.selectedvalue = myobject.property3 

but in both cases dropdownlist2 shows no selected item.

note: since textbox.text right value don't think search method has problem, that's why i'm not posting it.

it doesn't work way unfortunately. i'll give pseudocode since i'm c#er, how it:

dim int = 0 foreach item in ddl.items     if item.text = databaseresult         ddl.selectedindex =         exitloop     endif     = + 1 endforeach 

here working code comment thread below:

dim integer = 0  each listitem in dropdownlist1.items      if dropdownlist3.selecteditem.text = myobject.property          dropdownlist3.selectedindex =          exit      end if      = + 1  next 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -