my databound dropdownlist not populating, i've looked @ other threads here , haven't seem help. i'm not getting errors or , webform loads find. other database implementation working correctly. has simple i'm missing. i've implemented if(!ispostback){ddlbatchcodebind();
page load , did not either.
public void ddlbatchcodedelbind() { using (sqlconnection conn = new sqlconnection(getconnectionstring())) { try { sqldataadapter ada = new sqldataadapter("select batchcode, batchcodedesc batchtable", conn); datatable batch_codes = new datatable(); ada.fill(batch_codes); ddlbatchcodedel.datasource = batch_codes; ddlbatchcodedel.datatextfield = "batchcodedesc"; ddlbatchcodedel.datavaluefield = "batchcode"; ddlbatchcodedel.databind(); } catch(sqlexception ex) { messagebox.show(ex.message); } { conn.close(); } } } <asp:dropdownlist id="ddlbatchcodede" runat="server" appenddatabounditems="true"><asp:listitem text=select item delete" value="0"> </asp:listitem></asp:dropdownlist>
here alternative way can bind datatable without using sqldataadapter
using (sqlconnection conn = new sqlconnection(getconnectionstring())) using (sqlcommand cmd = new sqlcommand("select batchcode, batchcodedesc batchtable", conn)) { try { conn.open(); datatable batch_codes = new datatable(); batch_codes.load(cmd.executereader()); ddlbatchcodedel.datasource = batch_codes; ddlbatchcodedel.datatextfield = "batchcodedesc"; ddlbatchcodedel.datavaluefield = "batchcode"; ddlbatchcodedel.databind(); } catch (exception ex) { response.write(ex.message); } }
Comments
Post a Comment