Saturday, 15 March 2014

c# - Dropdownlist Databind automatically setting selected value? -



c# - Dropdownlist Databind automatically setting selected value? -

i filled dropdownlist active directory users, not big deal , works great. problem it's setting <option selected="selected" value="user">user</option> on first 1 , won't allow me alter in code behind. there way maintain automatically setting selected="selected"?

<asp:dropdownlist id="dlst" runat="server" width="200px" autopostback="true" datasourceid="dlstvalues" datatextfield="name" appenddatabounditems="true"> <asp:listitem>-- select --</asp:listitem> </asp:dropdownlist>

or should work:

protected void page_load(object sender, eventargs e) { if (!ispostback) { dropdownlist1.appenddatabounditems = true; dropdownlist1.items.insert(0, new listitem(string.empty, string.empty)); dropdownlist1.selectedindex = 0; } }

c# asp.net data-binding

No comments:

Post a Comment