Aspx code
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<style type="text/css">
.hidden
{
display:none;
}
.visible
{
display:block;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<table>
<tr>
<td>
Publish Date
</td>
<td>
<asp:Panel ID="MainPanel" runat="server"></asp:Panel>
</td>
</tr>
</table>
</asp:Content>
cs code
protected void Page_Load(object sender, EventArgs e)
{
RadioButtonList rbRadioButtonList = new RadioButtonList();
rbRadioButtonList.Items.Add(new ListItem("Date", "Date"));
rbRadioButtonList.Items.Add(new ListItem("DateRange", "DateRange"));
rbRadioButtonList.Items[0].Selected = true;
rbRadioButtonList.AutoPostBack = true;
rbRadioButtonList.RepeatDirection = RepeatDirection.Horizontal;
rbRadioButtonList.SelectedIndexChanged += new EventHandler(rbRadioButtonList_SelectedIndexChanged);
MainPanel.Controls.Add(rbRadioButtonList);
Panel datePanel = new Panel();
datePanel.BackColor = Color.Green;
datePanel.Height = 20;
datePanel.Width = 300;
datePanel.ID = "Date";
datePanel.CssClass = "visible";
Panel dateRangePanel = new Panel();
dateRangePanel.BackColor = Color.Red;
dateRangePanel.Height = 20;
dateRangePanel.Width = 300;
dateRangePanel.ID = "DateRange";
dateRangePanel.CssClass = "hidden";
MainPanel.Controls.Add(datePanel);
MainPanel.Controls.Add(dateRangePanel);
}
void rbRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rbRadioButtonList = (RadioButtonList)sender;
string value = rbRadioButtonList.SelectedItem.Text;
ContentPlaceHolder mpContentPlaceHolder;
mpContentPlaceHolder =(ContentPlaceHolder)Master.FindControl("MainContent");
if (mpContentPlaceHolder != null)
{
Panel DateRange = (Panel)mpContentPlaceHolder.FindControl("DateRange");
Panel Date = (Panel)mpContentPlaceHolder.FindControl("Date");
if (Date != null && DateRange!=null)
{
if (value=="DateRange")
{
DateRange.CssClass = "visible";
Date.CssClass = "hidden";
}
else
{
DateRange.CssClass = "hidden";
Date.CssClass = "visible";
}
}
}
}
No comments:
Post a Comment