<%@ 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 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 counter = 0;
foreach (ListItem litem in BulletedList1.Items)
{
if (litem.Text == li.Text)
{
counter += 1;
}
}
if (counter > 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 deselect Calendar selected date on second click</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:SlateBlue; font-style:italic;">
How to deselect Calendar selected date on second click
</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"
>
<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"
/>
<OtherMonthDayStyle BackColor="Tomato" />
<SelectedDayStyle
BackColor="Green"
BorderColor="MediumSeaGreen"
/>
<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 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 counter = 0;
foreach (ListItem litem in BulletedList1.Items)
{
if (litem.Text == li.Text)
{
counter += 1;
}
}
if (counter > 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 deselect Calendar selected date on second click</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:SlateBlue; font-style:italic;">
How to deselect Calendar selected date on second click
</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"
>
<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"
/>
<OtherMonthDayStyle BackColor="Tomato" />
<SelectedDayStyle
BackColor="Green"
BorderColor="MediumSeaGreen"
/>
<TitleStyle
BackColor="MidnightBlue"
Height="36"
Font-Size="Large"
Font-Names="Courier New Baltic"
/>
</asp:Calendar>
</div>
</form>
</body>
</html>
No comments:
Post a Comment