You can bind the dropdownlist with the above code. Maybe you have bound the dropdownlist or other control in the .aspx page. And your error can be caused by it. You can remove it and bind the dropdownlist from the code behind. You can also bind the dropdownlist
in the .aspx page. You can refer to the below code.
Qi Wu - MSFT
Contributor
5794 Points
677 Posts
Re: dropdown list databinding in the create user wizard control
Apr 16, 2012 03:27 AM|LINK
Hi,
You can bind the dropdownlist with the above code. Maybe you have bound the dropdownlist or other control in the .aspx page. And your error can be caused by it. You can remove it and bind the dropdownlist from the code behind. You can also bind the dropdownlist in the .aspx page. You can refer to the below code.
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" DataTextField="ProductID" DataValueField="ProductID" DataSourceID="SqlDataSource1" /> <asp:label runat="server" associatedcontrolid="UserName" id="UserNameLabel"> User Name:</asp:label> <asp:TextBox ID="UserName" runat="server"></asp:TextBox> <asp:textbox runat="server" textmode="Password" id="Password"></asp:textbox> <asp:textbox runat="server" textmode="Password" id="ConfirmPassword"></asp:textbox> <asp:textbox runat="server" id="Question"></asp:textbox> <asp:textbox runat="server" id="Answer"></asp:textbox> <asp:textbox runat="server" id="Email"></asp:textbox> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>" SelectCommand="SELECT [ProductID] FROM [Products]" ></asp:SqlDataSource> </ContentTemplate> </asp:CreateUserWizardStep> <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"> </asp:CompleteWizardStep> </WizardSteps> </asp:CreateUserWizard>The below code is in the code-behind.
protected void Page_Load(object sender, EventArgs e) { string[] array = new string[] { "apple", "orange", "banana" }; DropDownList ddl = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownList1") as DropDownList; ddl.DataSource = array; ddl.DataBind(); }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework