asp.net - DropDownList doesn't work with the codebehind C# -
so tried make dropdownlist. working when inside aspx file, doesn't work inside codebehind.
<asp:panel id="pnlchannel" runat="server"> <asp:sqldatasource id="sdschannel" runat="server" connectionstring="<%$ connectionstrings:monitor_sql %>" selectcommand="select * table"></asp:sqldatasource> <asp:dropdownlist id="ddlchannel" runat="server" datasourceid="sdschannel" autopostback="true" datatextfield="kanal"> </asp:dropdownlist> </asp:panel>
then tried codebehind in c#:
public panel getdropdownlist() { // create drop down list , data source panel pnlchannel = new panel(); pnlchannel.id = "pnlchannel"; dropdownlist ddlchannel = new dropdownlist(); ddlchannel.id = "ddlchannel"; listitem limdefault = new listitem(); sqldatasource sdschannel = new sqldatasource(); sdschannel.id = "sdschannel"; // configure data source sdschannel.connectionstring = configurationmanager.connectionstrings["monitor_sql"].connectionstring; sdschannel.selectcommand = "select * table"; // configure drop down list ddlchannel.datatextfield = "kanal"; ddlchannel.datavaluefield = "kanal"; ddlchannel.appenddatabounditems = true; ddlchannel.datasourceid = "sdschannel"; ddlchannel.autopostback = true; // configure default list item limdefault.selected = true; limdefault.text = "alle"; limdefault.value = "-1"; //add controls static panel in footer ddlchannel.items.add(limdefault); pnlchannel.controls.add(ddlchannel); pnlchannel.controls.add(sdschannel); return pnlchannel; }
why isn't working? + not use both, want use 1 of these opinions
based on comment:
if if in codebehind there dropdownlist there nothing inside list
you never bound control data:
ddlchannel.databind();
Comments
Post a Comment