Changing Usercontrols of a page based on dropdownlist values

Sandhyab
Posted by Sandhyab under ASP.NET category on | Points: 40 | Views : 1002
ASPX:
 <div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="UserControl1" Value="0"></asp:ListItem>
<asp:ListItem Text="UserControl2" Value="1"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnClick" runat="server" Text="Click" OnClick="Click" />
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
</div>


Code Behind
 protected void Click(object sender, EventArgs e)
{
string SelectedValue = DropDownList1.SelectedItem.Value;
if (SelectedValue == "0")
{

Panel1.Controls.Add(LoadControl("./WebUserControl1.ascx"));
}
else
{
Panel1.Controls.Add(LoadControl("./WebUserControl2.ascx"));
}
}

Comments or Responses

Login to post response