Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I want to Add Calendar control programmatically in Panel.
In my form there is Start Date and End Date and Show Button.
When I Press Show Button That time I want to Add calendar between this two date in Panel like Start Date is "1st Aug 2012" and End Date is "25th Sep 2012" that time there is two calendar control place in Panel.
And also there is one condition for change Background color of Every Sunday in this two calendar.

Please help me.
Posted

ASP .NET Ajax Toolkit has working samples to resolve your problem. You need to expand the item labeled Calendar Theming. Ref: http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/calendar/calendar.aspx[^]
 
Share this answer
 
Comments
Savalia Manoj M 20-Aug-12 23:37pm    
Thanks for Answer GanesanSenthilvel But i am not use Ajax control.
Please give me code if you have change Background color of date in Control.
Thanks.
Hi all,
I Got logic for how to add Calendar in panel like this,
In My ASPX page looks Like,

<table>
       <tr>
           <td>
               <asp:label id="Label1" runat="server" text="Start Date:" xmlns:asp="#unknown"></asp:label>
               <asp:textbox runat="server" id="txtStart" xmlns:asp="#unknown"></asp:textbox>
               <asp:calendar id="Calendar1" runat="server" onselectionchanged="Calendar1_SelectionChanged" xmlns:asp="#unknown">
               </asp:calendar>
           </td>
           <td rowspan="3">
               <asp:panel id="pnlContaint" runat="server" height="100%" width="100%" xmlns:asp="#unknown">
               </asp:panel>
           </td>
       </tr>
       <tr>
           <td>
               <asp:label id="Label2" runat="server" text="End Date:" xmlns:asp="#unknown"></asp:label>
               <asp:textbox runat="server" id="txtEndDate" xmlns:asp="#unknown"></asp:textbox>
               <asp:calendar id="Calendar2" runat="server" onselectionchanged="Calendar2_SelectionChanged" xmlns:asp="#unknown">
               </asp:calendar>
           </td>
           <td>
           </td>
       </tr>
       <tr>
           <td>
               <asp:label id="Label3" runat="server" text="Every:" xmlns:asp="#unknown"></asp:label>
               <asp:dropdownlist id="DropDownList1" runat="server" xmlns:asp="#unknown">
                   <asp:listitem value="1">Every</asp:listitem>
                   <asp:listitem value="2">Every 2nd</asp:listitem>
                   <asp:listitem value="3">Every 3rd</asp:listitem>
               </asp:dropdownlist>
               <asp:button id="Button1" runat="server" text="Show" onclick="Button1_Click" xmlns:asp="#unknown" />
           </td>
           <td>
           </td>
       </tr>
       <tr>
           <td colspan="2">
           </td>
       </tr>
   </table>


In My Code,
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
   {
       txtStart.Text = Calendar1.SelectedDate.ToShortDateString();
   }
   protected void Calendar2_SelectionChanged(object sender, EventArgs e)
   {
       txtEndDate.Text = Calendar2.SelectedDate.ToShortDateString();
   }
   protected void Button1_Click(object sender, EventArgs e)
   {

       DateTime dtTemp = new DateTime(Calendar1.SelectedDate.Year, Calendar1.SelectedDate.Month, 1);
       while (dtTemp < Calendar2.SelectedDate)
       {

           Calendar cal = new Calendar();
           cal.ShowNextPrevMonth = false;
           cal.TodaysDate = dtTemp.Date;
           cal.DayRender += new DayRenderEventHandler(cal_DayRender);
           pnlContaint.Controls.Add(cal);
           dtTemp = dtTemp.AddMonths(1);
       }
   }

   void cal_DayRender(object sender, DayRenderEventArgs e)
   {
       e.Day.IsSelectable = false;
   }



But there is one Problem is that how to change Background In Date?
Please Help me...
 
Share this answer
 
Comments
AmitGajjar 21-Aug-12 0:04am    
if you have any changes in question then Improve your question. don't post it in solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900