<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsSelected)
{
CheckBox CheckBox1 = new CheckBox();
CheckBox1.Checked = true;
CheckBox1.Width = 25;
CheckBox1.Enabled = false;
e.Cell.Controls.AddAt(1, CheckBox1);
e.Cell.Font.Size = FontUnit.XLarge;
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack && Calendar1.SelectedDates.Count ==1)
{
Calendar1.SelectedDates.Clear();
}
}
protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
ListItem li = new ListItem();
li.Text = Calendar1.SelectedDate.ToShortDateString();
int itemCounter = 0;
foreach (ListItem litem in BulletedList1.Items)
{
if (litem.Text == li.Text)
{
itemCounter += 1;
}
}
if (itemCounter > 0)
{
BulletedList1.Items.Remove(li);
}
else
{
BulletedList1.Items.Add(li);
}
Calendar1.SelectedDates.Clear();
SelectedDatesCollection dates = Calendar1.SelectedDates;
foreach (ListItem litem in BulletedList1.Items)
{
DateTime date = Convert.ToDateTime(litem.Text);
dates.Add(date);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to add CheckBox control in Calendar Day Cell</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:SlateBlue; font-style:italic;">
How to add CheckBox control in Calendar Day Cell
</h2>
<hr width="600" align="left" color="SlateGray" />
<asp:BulletedList
ID="BulletedList1"
runat="server"
Visible="false"
>
</asp:BulletedList>
<asp:Calendar
ID="Calendar1"
runat="server"
NextPrevFormat="FullMonth"
ForeColor="WhiteSmoke"
SelectionMode="Day"
DayNameFormat="Full"
Font-Names="Book Antiqua"
Font-Size="Medium"
OnSelectionChanged="Calendar1_SelectionChanged"
OnDayRender="Calendar1_DayRender"
>
<DayHeaderStyle
BackColor="OliveDrab"
/>
<DayStyle
BackColor="DarkOrange"
BorderColor="Orange"
BorderWidth="1"
Font-Bold="true"
Font-Italic="true"
Font-Size="Large"
/>
<NextPrevStyle
Font-Italic="true"
Font-Names="Arial CE"
/>
<SelectedDayStyle
BackColor="DarkOrange"
BorderColor="Pink"
/>
<TitleStyle
BackColor="MidnightBlue"
Height="36"
Font-Size="Large"
Font-Names="Courier New Baltic"
/>
</asp:Calendar>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsSelected)
{
CheckBox CheckBox1 = new CheckBox();
CheckBox1.Checked = true;
CheckBox1.Width = 25;
CheckBox1.Enabled = false;
e.Cell.Controls.AddAt(1, CheckBox1);
e.Cell.Font.Size = FontUnit.XLarge;
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack && Calendar1.SelectedDates.Count ==1)
{
Calendar1.SelectedDates.Clear();
}
}
protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
ListItem li = new ListItem();
li.Text = Calendar1.SelectedDate.ToShortDateString();
int itemCounter = 0;
foreach (ListItem litem in BulletedList1.Items)
{
if (litem.Text == li.Text)
{
itemCounter += 1;
}
}
if (itemCounter > 0)
{
BulletedList1.Items.Remove(li);
}
else
{
BulletedList1.Items.Add(li);
}
Calendar1.SelectedDates.Clear();
SelectedDatesCollection dates = Calendar1.SelectedDates;
foreach (ListItem litem in BulletedList1.Items)
{
DateTime date = Convert.ToDateTime(litem.Text);
dates.Add(date);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to add CheckBox control in Calendar Day Cell</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:SlateBlue; font-style:italic;">
How to add CheckBox control in Calendar Day Cell
</h2>
<hr width="600" align="left" color="SlateGray" />
<asp:BulletedList
ID="BulletedList1"
runat="server"
Visible="false"
>
</asp:BulletedList>
<asp:Calendar
ID="Calendar1"
runat="server"
NextPrevFormat="FullMonth"
ForeColor="WhiteSmoke"
SelectionMode="Day"
DayNameFormat="Full"
Font-Names="Book Antiqua"
Font-Size="Medium"
OnSelectionChanged="Calendar1_SelectionChanged"
OnDayRender="Calendar1_DayRender"
>
<DayHeaderStyle
BackColor="OliveDrab"
/>
<DayStyle
BackColor="DarkOrange"
BorderColor="Orange"
BorderWidth="1"
Font-Bold="true"
Font-Italic="true"
Font-Size="Large"
/>
<NextPrevStyle
Font-Italic="true"
Font-Names="Arial CE"
/>
<SelectedDayStyle
BackColor="DarkOrange"
BorderColor="Pink"
/>
<TitleStyle
BackColor="MidnightBlue"
Height="36"
Font-Size="Large"
Font-Names="Courier New Baltic"
/>
</asp:Calendar>
</div>
</form>
</body>
</html>
No comments:
Post a Comment