c# - Dropdown gets cleared -
i have 1 asp.net application, in have 1 dropdown binded dataset. after selecting 1 item, drop down gets cleared value, how can resolve issue?
this dropdown list in design page:
<asp:dropdownlist id="ddlproduct" runat="server" cssclass="textentry" width="300px" autopostback="true" onselectedindexchanged="ddlproduct_selectedindexchanged"> </asp:dropdownlist>
and binding code shown below.
protected void page_load(object sender, eventargs e) { if (!ispostback) bindproductddl(); } private void bindproductddl() { products objproducts = new products(); dsproducts dsproduct = new dsproducts(); listitem olst = default(listitem); olst = new listitem(" select", "0"); dsproduct = objproducts.getdataset(""); ddlproduct.datasource = dsproduct; ddlproduct.datatextfield = "product"; ddlproduct.datavaluefield = "id"; ddlproduct.databind(); ddlproduct.items.insert(0, olst); } protected void ddlproduct_selectedindexchanged(object sender, eventargs e) { products objproducts = new products(); dsproducts dsproduct = new dsproducts(); string criteria = ""; if (ddlproduct.selecteditem.text != " select") { string id = ddlproduct.selecteditem.value; criteria = "id='" + id + "'"; dsproduct = objproducts.getdataset(criteria); productvalue = convert.todecimal(dsproduct.tblproducts.rows[0]["value"].tostring()); } }
thanks in advance..
from question if understand correctly dont want dropdown list rebind if populated. please check viewstate, should not happening, unless have disabled viewstate
protected void page_load(object sender, eventargs e) { if (!ispostback && ddlproduct.items.count <=0 ) bindproductddl();
}
Comments
Post a Comment