Categories
Asp, Asp.net

How To Add Text With Day In Calendar In ASP.NET Example

How To Add Text With Day In Calendar In ASP.NET Example

In this tutorial we will learn How To Add Text With Day In Calendar In ASP.NET Example.DayRender event provides such types of functionality, You can change specific day at run time.

Design:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How-To-Add-Text-With-Day-In-Calendar-In-ASP.NET-Example</title>
<style type="text/css">
body
 {
 width: 980px;
 margin: 0px auto;
 text-align: center;
 padding-top: 50px;
 font-size: 16px;
 }
</style>

</head>
<body>
<form id="form1" runat="server">
<h2>How To Add Text With Day In Calendar In ASP.NET Example</h2>
<div style="width:100%;text-align:center;margin:0px auto">
<asp:Calendar ID="cal" OnDayRender="cal_DayRender" runat="server" Width="100%" NextPrevFormat="FullMonth">
<NextPrevStyle Font-Size="16px" verticalAlign="Bottom" Font-Underline="false" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="Blue" />
<TitleStyle BackColor="White" ForeColor="#333399" />
<TodayDayStyle  BackColor="Yellow" />
</asp:Calendar> 
<br /><br />
<br /><br />
All rights reserved by <a href="http://www.hightechnology.in">www.Hightechnology.in</a> | Hosting partner <a href="http://www.grootstech.com" target="_blank">Grootstech</a>
  
</div>
</form>
</body>
</html>

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void cal_DayRender(object sender, DayRenderEventArgs e)
    { 
        if (e.Day.DayNumberText =="9")
        {
            e.Cell.Controls.Add(new LiteralControl("<br/>Holiday"));
        }
    }
}