c# - DropdownList is not showing the selected value -


i have used dropdownlist in repeater. fetches designation (admin,manager,member) database. user name displayed correctly, alert showing correct data. dropdownlist.selecteditem has no effect. both users shows admin in dropdown default selected value, in db manager.

protected void listrepeaterview_itemdatabound(object sender, repeateritemeventargs e) {        dropdownlist selectlist = e.item.findcontrol("dropdownlist1") dropdownlist;     selectlist.datasource = ml.selectall();     selectlist.datatextfield = "designation";     selectlist.datavaluefield = "employeeid";      selectlist.databind();       hiddenfield designation = (hiddenfield)e.item.findcontrol("hdndesignation");    selectlist.selectedvalue = designation.value.tostring();    scriptmanager.registerclientscriptblock(this, this.gettype(), "alertmessage", "alert(" + designation.value.tostring() + ");", true);     } 

.cs file

    <asp:repeater id="listrepeaterview" runat="server" onitemdatabound="listrepeaterview_itemdatabound"> <itemtemplate><tr><td> <asp:label id="empname" runat="server" text='<%# eval("employeename") %>'></asp:label>  asp:hiddenfield id="hdnproductid" value='<%# eval("employeeid") %>' runat="server" /> </td><td> <asp:hiddenfield id="hdndesignation" value='<%# eval("designation") %>' runat="server" /> <asp:dropdownlist id="dropdownlist1" runat="server" appenddatabounditems="true" >  </asp:dropdownlist> </td></tr> <br /><br /><br /> </itemtemplate> </asp:repeater> 

you using "designation" text field , "employeeid" value field in select. , try set selected value based on "designation". cannot work.

what can locate default item text:

// add error handling cases when item cannot found var defaulttext = designation.value.tostring(); selectlist.items.findbytext(defaulttext).selected = true; 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -