c# - Why is my DropDownList not working? -
i display dropdownlist isn't working yet. asp.net code:
<asp:panel id="pnlchannel" runat="server"> <asp:sqldatasource id="sdschannel" runat="server"></asp:sqldatasource> <asp:dropdownlist id="ddlchannel" runat="server"> <asp:listitem id="limdefault" runat="server"></asp:listitem> </asp:dropdownlist> </asp:panel>
and codebehind:
public panel getdropdownlist() { // create drop down list , data source panel pnlchannel = new panel(); dropdownlist ddlchannel = new dropdownlist(); listitem limdefault = new listitem(); sqldatasource sdschannel = new sqldatasource(); // configure data source sdschannel.connectionstring = configurationmanager.connectionstrings["cr_sql"].connectionstring; sdschannel.selectcommand = "select * table"; sdschannel.id = "sdschannel"; // configure drop down list ddlchannel.datatextfield = "channel"; ddlchannel.datavaluefield = "channel"; ddlchannel.appenddatabounditems = true; ddlchannel.datasourceid = "sdschannel"; // configure default list item limdefault.selected = true; limdefault.text = "all"; limdefault.value = "-1"; // add controls static panel in footer ddlchannel.items.add(limdefault); pnlchannel.controls.add(ddlchannel); pnlchannel.controls.add(sdschannel); return pnlchannel; }
did miss something? think listitem isn't working, because there dropdownlist can't see list drop down.
you have not set text
property of listitem
. remove code .cs
file creating controls because duplicate controls.
<asp:dropdownlist id="ddlchannel" runat="server"> <asp:listitem id="limdefault" runat="server" text="sometext" value="somevalue"></asp:listitem> </asp:dropdownlist>
Comments
Post a Comment