I'm again having a problem with the working of my calendar control. Hope you people can help me out.
In this calendar, if I wish to remove some holidays and mark as normal days, how should I do that?
I don't know where I'm going wrong, but I would like to share what I have done, may be you can point out my mistake...
There is a table in the database to store holidays. In front end, I have used dayRender event to highlight holidays and normal days.Now once I click on the "holiday" to remove it from the table, it should be removed. But alas, that doesnot happen. The table
in the backend remains unchanged. For deleting the record I have created a stored procedure, and I have stored it in the .cs file. the table only has two columns ID and Date.
Where am I going wrong? Can you pl tell? So that I can rectify my problem...
coolpal9
Member
164 Points
538 Posts
calendar control: how to remove holidays and update it in the database
Mar 30, 2012 06:03 AM|LINK
Hi,
I'm again having a problem with the working of my calendar control. Hope you people can help me out.
In this calendar, if I wish to remove some holidays and mark as normal days, how should I do that?
I don't know where I'm going wrong, but I would like to share what I have done, may be you can point out my mistake...
There is a table in the database to store holidays. In front end, I have used dayRender event to highlight holidays and normal days.Now once I click on the "holiday" to remove it from the table, it should be removed. But alas, that doesnot happen. The table in the backend remains unchanged. For deleting the record I have created a stored procedure, and I have stored it in the .cs file. the table only has two columns ID and Date.
Where am I going wrong? Can you pl tell? So that I can rectify my problem...
cninjas
Contributor
4868 Points
851 Posts
Re: calendar control: how to remove holidays and update it in the database
Mar 30, 2012 06:42 AM|LINK
hi
I am pasting the working sample here.hope it helps..
<div> <asp:Calendar ID="Calendar1" runat="server" BackColor="White" ondayrender="calDT_DayRender" BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="502px" NextPrevFormat="FullMonth" Width="716px"> <SelectedDayStyle BackColor="#333399" ForeColor="White" /> <TodayDayStyle BackColor="#CCCCCC" /> <OtherMonthDayStyle ForeColor="#999999" /> <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" /> <DayHeaderStyle Font-Bold="True" Font-Size="8pt" /> <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True" Font-Size="12pt" ForeColor="#333399" /> </asp:Calendar> </div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> <asp:LinkButton ID="CalendarLinkButton" Visible=false runat="server" CssClass="hide" OnClick="CalendarLinkButton_Click"></asp:LinkButton>List<DateTime> dtholidays = null; protected void Page_Load(object sender, EventArgs e) { dtholidays = GetPublicHolidays(); } protected void calDT_DayRender(object sender, DayRenderEventArgs e) { if (dtholidays.Contains(e.Day.Date)) { e.Cell.Controls.Add(new LiteralControl("<br /><font color=red>Holiday</font>")); HyperLink link = new HyperLink(); link.CssClass = "activity"; link.ImageUrl = "del.png"; link.ToolTip = e.Day.Date.ToString(); link.NavigateUrl = Page.ClientScript.GetPostBackClientHyperlink(CalendarLinkButton,e.Day.Date.ToString(), true); e.Cell.Controls.Add(link); } } public void onCalendarImageClick(object sender, ImageClickEventArgs e) { } private List<DateTime> GetPublicHolidays() { List<DateTime> list = new List<DateTime>(); //populate from database or other sources list.Add(new DateTime(2012, 01, 01)); list.Add(new DateTime(2012, 02, 02)); list.Add(new DateTime(2012, 02, 14)); list.Add(new DateTime(2012, 03, 02)); list.Add(new DateTime(2012, 03, 14)); list.Add(new DateTime(2012, 04, 02)); list.Add(new DateTime(2012, 04, 14)); list.Add(new DateTime(2012, 05, 02)); list.Add(new DateTime(2012, 05, 14)); list.Add(new DateTime(2012, 06, 02)); list.Add(new DateTime(2012, 06, 14)); list.Add(new DateTime(2012, 07, 02)); list.Add(new DateTime(2012, 07, 14)); list.Add(new DateTime(2012, 08, 02)); list.Add(new DateTime(2012, 08, 14)); list.Add(new DateTime(2012, 09, 02)); list.Add(new DateTime(2012, 09, 14)); list.Add(new DateTime(2012, 10, 02)); list.Add(new DateTime(2012, 10, 14)); list.Add(new DateTime(2012, 11, 02)); list.Add(new DateTime(2012, 11, 14)); list.Add(new DateTime(2012, 12, 02)); list.Add(new DateTime(2012, 12, 14)); return list; } protected void CalendarLinkButton_Click(object sender, EventArgs e) { Response.Write(Request.Form["__EVENTARGUMENT"]); }Niranjan
coolpal9
Member
164 Points
538 Posts
Re: calendar control: how to remove holidays and update it in the database
Mar 30, 2012 08:11 AM|LINK
I've already tried this code, and its not working. List<DateTime> doesnot get recognised.
Can you help me with doing so via stored procedures..?
cninjas
Contributor
4868 Points
851 Posts
Re: calendar control: how to remove holidays and update it in the database
Mar 30, 2012 08:38 AM|LINK
hi
just paste the code you have written for geting it from the stored procedure..we will help you frm tat//
Niranjan
coolpal9
Member
164 Points
538 Posts
Re: calendar control: how to remove holidays and update it in the database
Mar 30, 2012 09:24 AM|LINK
Ok will do that.
coolpal9
Member
164 Points
538 Posts
Re: calendar control: how to remove holidays and update it in the database
Mar 30, 2012 09:28 AM|LINK
Here is the code:
public DataTable FetchHoliday()
{
try
{
return SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, "[usp_SHR_BDM_Fetch_Holiday_Master]").Tables[0];
}
catch (Exception ex)
{
throw ex;
}
}
cninjas
Contributor
4868 Points
851 Posts
Re: calendar control: how to remove holidays and update it in the database
Mar 30, 2012 10:05 AM|LINK
protected void Page_Load(object sender, EventArgs e) { dtholidays1 = FetchHoliday(); } protected void calDT_DayRender(object sender, DayRenderEventArgs e) { DataRow[] result = dtholidays1.Select("day_Text = '" + e.Day.Date + "'"); if (result != null && result.Length > 0) { e.Cell.Controls.Add(new LiteralControl("<br /><font color=red>Holiday</font>")); HyperLink link = new HyperLink(); link.CssClass = "activity"; link.ImageUrl = "del.png"; link.ToolTip = e.Day.Date.ToString(); link.NavigateUrl = Page.ClientScript.GetPostBackClientHyperlink(CalendarLinkButton, e.Day.Date.ToString(), true); e.Cell.Controls.Add(link); } }and my data for date from the database is
Hope it helps you now..thanks...
refer to my previous post for button click and other stuffs...thanks,
Niranjan
coolpal9
Member
164 Points
538 Posts
Re: calendar control: how to remove holidays and update it in the database
Apr 03, 2012 07:24 AM|LINK
What is day_Text? Is it the column name of your database table?
cninjas
Contributor
4868 Points
851 Posts
Re: calendar control: how to remove holidays and update it in the database
Apr 03, 2012 07:37 AM|LINK
hi
Yes day_Text is the name of the column.
Niranjan
coolpal9
Member
164 Points
538 Posts
Re: calendar control: how to remove holidays and update it in the database
Apr 03, 2012 08:06 AM|LINK
Thanks a ton @cninjas!! I finally got it! Last time I had missed out some little things, so was in vain, now I feel relieved. Thanks again!