Display selected Date from data base into asp.net calendar

Display selected Date from data base into calendar in asp.net Programming:



 In the ASP.NET Programming we can easily access holiday list from data base, but here we goes to discuss how to bind these holiday’s in to calendar tool. As we know that calendar is use for representing to the data time in asp.net.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

This line use for register ajax toolkit in the page :

The Calendar control is used to display a calendar in the browser.This control displays a one-month calendar that allows the user to select dates and move to the next and previous months.
The Calendar control display a graphic calendar on which users can select dates. This control exists within System.

Web.UI.WebControls namespace. You can use the Calendar control to display a single month of a calendar on a Web page . This control allows you to select dates and move to the next or previous month. By Setting the SelectionMode property , You can select a single day , week, or month.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

This line use for register ajax toolkit in the page :

Code for ASPX File:

<asp:UpdatePanel ID="up1" runat="server">
                                    <ContentTemplate>
                                        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="White"
                                            BorderStyle="None" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
                                            Height="219px" NextPrevFormat="ShortMonth" OnDayRender="Calendar1_DayRender"
                                            TitleFormat="MonthYear" Width="100%">
                                            <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
                                            <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
                                            <OtherMonthDayStyle ForeColor="#999999" />
                                            <SelectedDayStyle BackColor="#333399" ForeColor="White" />
                                            <TitleStyle BackColor="White" Font-Bold="true" Font-Size="11pt" ForeColor="#333399"
                                                HorizontalAlign="Center" VerticalAlign="Middle" />
                                            <TodayDayStyle BackColor="#CCCCCC" />
                                        </asp:Calendar>
                                        <cc1:RoundedCornersExtender ID="Calendar1_RoundedCornersExtender" runat="server"
                                            Enabled="True" TargetControlID="Calendar1">
                                        </cc1:RoundedCornersExtender>
                                    </ContentTemplate>
                                </asp:UpdatePanel>

Code for ASPX.CS File:

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        Literal l = new Literal();
        l.Visible = true;
        //l.Text = "<br/>";
        e.Cell.Controls.Add(l);
        dt = (DataTable)ViewState["dt"];
        foreach (DataRow row in dt.Rows)
        {
            if (Convert.ToDateTime(row[0].ToString()).ToShortDateString() == e.Day.Date.ToShortDateString())
            {
                Label lb = new Label();
                lb.Visible = true;
                String s = row[1].ToString();
                s = s.Substring(0, 0);
                lb.Text = s.ToString();
                s = "";
               
                lb.Text = row[2].ToString();
                e.Cell.BackColor = System.Drawing.Color.FromArgb(132, 207, 150);
                e.Cell.ForeColor = System.Drawing.Color.WhiteSmoke;
                e.Cell.Controls.Add(lb);
            }
        }
    }






OtherAsp.net related post:

Comments

Popular posts from this blog