c# - Checkboxlist loop is not working -
i have dropdownlist control , button in asp.net page. dropdownlist populated method. if select item other first item, after clicking button, lose selected item in ddl , selects first item , getting value of first item in button click event. how can fix problem?
<asp:dropdownlist id="userdropdown" runat="server" datatextfield="customername" datavaluefield="customerid"> </asp:dropdownlist> protected void button1_click(object sender, eventargs e) { if(!page.ispostback) { userdropdown.datasource = cc.getcustomers(); userdropdown.databind(); } }
it sounds binding dropdownlist datasource @ ever request. instead bind if page.ispostback
false below; (you may not need objectdatasource
)
protected void page_load(object sender, eventargs e) { if (!page.ispostback) { //bind datasource here (something below) userdropdown.datasource = getcustomers(); userdropdown.databind(); } }
as databind() method called lose posted data of object , firstitem selected default.
Comments
Post a Comment