Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:31:57+00:00 2026-06-09T17:31:57+00:00

I have a calendar control that I was filling with different events. When one

  • 0

I have a calendar control that I was filling with different events. When one event only spans one day I wanted it to change the linkbutton color to red.

 public partial class RequestCalander : System.Web.UI.Page
{
    private DataSet GetData()
    {
        ConnectionStringSettingsCollection cssc = ConfigurationManager.ConnectionStrings;

        var sql = "select (substring(status, 1,1)) AS stat1, lastname, firstname, lstdate, lenddate, requestid from [table] E inner join [tableEvent] T on E.EMPID = T.emppid where E.depdivid = '" + @UsrDepartment + "'";

        using (iDB2Connection conn = new iDB2Connection(GetConnectionString()))
        {
            conn.Open();

            using (iDB2Command cmd = new iDB2Command(sql, conn))
            {
                cmd.DeriveParameters();

                using (iDB2DataAdapter da = new iDB2DataAdapter(cmd))
                {
                    DataSet ds = new DataSet();
                    da.Fill(ds);

                    return ds;
                }
            }
        }
    }

    private String GetConnectionString()
    {
        ConnectionStringSettingsCollection cssc = ConfigurationManager.ConnectionStrings;

        return cssc["connStringEvent"].ToString();
    }

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        e.Cell.Width = 150;
        e.Cell.Height = 100;
        DataSet ds = GetData();

        string link = "<a class='turnred' href='viewRequestForm.aspx?bwrequestid=";

        string s = e.Day.Date.ToShortDateString();

        e.Cell.Text = e.Day.Date.Day.ToString() + "<BR>";

        LiteralControl l = new LiteralControl();
        l.Text = e.Day.Date.Day.ToString() + "<BR>";
        e.Cell.Controls.Add(l);

        foreach (DataRow row in ds.Tables[0].Rows)
        {
            string scheduledDate = Convert.ToDateTime(row["lstdate"]).ToShortDateString();
            string endDate = Convert.ToDateTime(row["lenddate"]).ToShortDateString();

            e.Cell.Width = 120;
            e.Cell.Height = 100;

            Int32 start = 0;
            Int32 end = 0;

            start = string.CompareOrdinal(scheduledDate, s);
            end = string.CompareOrdinal(endDate, s);

            if ((start > 0) || (end < 0) || (e.Day.IsWeekend == true))
            {
                return;
            }

            HyperLink hl = new HyperLink();
            hl.Text = "yes";

            if (scheduledDate.CompareTo(endDate) == 0){
                    hl.ForeColor = System.Drawing.Color.Red;

                e.Cell.Controls.Add(hl);
               }
                if ((start <= 0) & (end >= 0) & (!e.Day.IsWeekend))
                {
                    HyperLink lb = new HyperLink();
                    lb.Text = link + (Int64)row["bwrequestid"] + "' >" + row["lastname"] + "</a>" as String + "(" + row["stat1"] + ")" as String + "<br />";
                    lb.ForeColor = System.Drawing.Color.Red;
                    e.Cell.Controls.Add(lb);
                    lb.NavigateUrl = "~/Form.aspx?requestid={0}";
    }
}

}

aspx code

    <%@ Page Title="Leave Request" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Calander.aspx.cs" Inherits="RequestCalander" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<%@ Register TagPrefix="ec" Namespace="ControlSample" Assembly="EventCalendar" %>


<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <link type="text/css" rel="Stylesheet" href="../../Styles/Calendar.css" /> 
    <style type="text/css">
        .style1{width: 782px;}
        .style2{width: 883px;}

    .changecolor { color: Red; }

    </style>
    </asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
                <table class="style1">
                        <tr>
                             <td class="style2">
                                 <table class="style4">
                                     <tr>
                                         <td>
                                           <asp:Button ID="backButton" runat="server" Text="Back"  Width="100" />
                                           <asp:Button ID="requestButton" runat="server" OnClick="goToPageRequest" Text="Make Request"  Width="100" />
                                          </td>
                                     </tr>
                                </table>
                            </td>
                        </tr>
                       <tr>
                           <td class="style2">
                            <asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender" Font-Size="Large" Width="901px" style="font-family: 'Times New Roman', Times, serif" >
                                <TitleStyle Font-Bold="true" Font-Size="X-large" BorderStyle="Solid" />
                                <DayHeaderStyle CssClass="caldays" Height="30px" BorderStyle="Solid" />
                                <DayStyle CssClass="calcurrentmonth" Font-Size="X-small" Height="100px" />
                                <TodayDayStyle CssClass="calcurrentday" Width="120px" Height="100px"/>
                                <WeekendDayStyle CssClass="calweekend" Width="120px" Height="100px"/>
                                <OtherMonthDayStyle CssClass="calothermonth" Width="120px" Height="100px"/>
                            </asp:Calendar>
                           </td>
                        </tr>
                </table>
</asp:Content>

The Css

/************************************************************************
* 
* Calendar specific formatting 
*
************************************************************************/

/* Surrounds the calendar */
.eventmonth
{
    padding-left: 1px;
    padding-right: 1px;
    padding-top: 1px;
    text-align: center;
}

.changecolor
{ 
    color:red;
}


/* used as the cssclass of the actual calendar */
.eventmonthtable
{
    margin-right: 0px;
    margin-left: 8px;
    position: relative;
    margin-bottom: 9px;
    border: 1px solid #666666;
    border-collapse:collapse;
    top: 1px;
    left: -228px;
    height: 38px;
    width: 722px;
}


.dayNumber
{
    color :Background;
    float: right;
    border-bottom: 1px solid #666666;
    border-left: 1px solid #666666;
    clear: none;
    padding: 2px;
}

.linkbutton
{
    color:red;
}
.calcurrentmonth
{

}
.calothermonth
{
    background-color: #6B9EB9;

}
.calcurrentday
{
    background-color: #B0C9FF;

}
.calweekend
{
    background-color: #6B9EB9;
}

.calcurrentmonth , .calcurrentmonth , .calothermonth , .calcurrentday , .calweekend
{

    text-align: left;
    border: 2px solid #000000;
    vertical-align: top;
    /* needed for positioning the dayNumber part */
    position:relative;
    border-collapse:separate;
    border-spacing: 2px;

}

.nextlink
{
    position:absolute;
    right:0;
    padding-right:15px;    
}

The links are contained in a calendar control.

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title>Attendance</title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                <h1>

                </h1>
                <asp:Table ID="Table1" runat="server">
                   <asp:TableRow>
                      <asp:TableCell>
                            <h2>ATTENDANCE&nbsp;
                            <img src="/images/LogoDrop.jpg" alt="" height="20" width="15" />
                            &nbsp;
                            EXCEPTION LEAVE TIME</h2>
                      </asp:TableCell>
                  </asp:TableRow>
                </asp:Table>
            </div>
            <div class="loginDisplay">
                <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                    <AnonymousTemplate>
                        [ <a href="/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                    </AnonymousTemplate>
                    <LoggedInTemplate>
                        Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                        [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="/Login.aspx"/> ]
                    </LoggedInTemplate>
                </asp:LoginView>
            </div>
            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" 
                    EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal" StaticDisplayLevels="1">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="PayPeriodProcessing" Selected="True"  ToolTip="Exception Leave Entry; Approval; Payroll " />
                        <asp:MenuItem NavigateUrl="~/Request/Time.aspx" Text="Leave Request" Selected="True"  ToolTip="Leave Request " />
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
                     </Items>
                </asp:Menu>
            </div>
        </div>
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="footer">
        <asp:Label ID="lblCopyright" runat="server"> </asp:Label>
    </div>
    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:31:59+00:00Added an answer on June 9, 2026 at 5:31 pm

    You may need to describe your code a bit further, but here are my initial thoughts.

    Code front

    <style type="text/css">
        .disabledbtn { color: Red; }
    </style>
    
    <asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender" Font-Size="Large" Width="901px" style="font-family: 'Times New Roman', Times, serif" >
        <TitleStyle Font-Bold="true" Font-Size="X-large" BorderStyle="Solid" />
        <DayHeaderStyle CssClass="caldays" Height="30px" BorderStyle="Solid" />
        <DayStyle CssClass="calcurrentmonth" Font-Size="X-small" Height="100px" />
        <TodayDayStyle CssClass="calcurrentday" Width="120px" Height="100px"/>
        <WeekendDayStyle CssClass="calweekend" Width="120px" Height="100px"/>
        <OtherMonthDayStyle CssClass="calothermonth" Width="120px" Height="100px"/>
    </asp:Calendar>
    

    Code behind

    The problem was that you were creating two links. One without any link text, which was set to be red and a second one that had the name and status.

    You’d never see the red text since it had no text to display. I’ve simplified your code a bit and it now works on my end.

    This is a fake DataSet that I created to test with, but yours should take the place of it.

    private DataSet GetData()
    {
        // create a test data set
        DataTable dt = new DataTable();
        dt.Columns.Add("stat1");
        dt.Columns.Add("lastname");
        dt.Columns.Add("firstname");
        dt.Columns.Add("lstdate");
        dt.Columns.Add("lenddate");
        dt.Columns.Add("bwrequestid");
    
        dt.Rows.Add("P", "Doe", "John", "08/16/2012", "08/16/2012", 1);
        dt.Rows.Add("P", "Doe", "Jane", "08/14/2012", "08/17/2012", 2);
        dt.Rows.Add("C", "Black", "Jack", "08/12/2012", "08/12/2012", 3);
        dt.Rows.Add("C", "Morgan", "Dexter", "08/01/2012", "08/07/2012", 4);
        dt.Rows.Add("S", "Swearengen", "Al", "08/15/2012", "08/20/2012", 5);
        dt.Rows.Add("S", "Kirk", "James T", "08/04/2012", "08/04/2012", 6);
        dt.Rows.Add("P", "Bundy", "Al", "08/07/2012", "08/07/2012", 7);
    
        DataSet ds = new DataSet();
        ds.Tables.Add(dt);
    
        return ds;
    }
    

    This should correctly render your calendar I believe. One thing I’m not certain on, do you want the weekend dates to always be red?

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        e.Cell.Width = 150;
        e.Cell.Height = 100;
        DataSet ds = GetData();
    
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            DateTime scheduledDate = Convert.ToDateTime(row["lstdate"]);
            DateTime endDate = Convert.ToDateTime(row["lenddate"]);
    
            // make sure it meets your criteria
            if ((e.Day.Date >= scheduledDate && e.Day.Date <= endDate))
            {
                // create the hyperlink
                HyperLink hl = new HyperLink();
                hl.Text = "<br />" + row["lastname"].ToString() + "(" + row["stat1"].ToString() + ")";
                hl.NavigateUrl = "~/Form.aspx?requestid=" + row["bwrequestid"].ToString();
    
                // if the start and end dates are the same day, make it red
                if (scheduledDate.CompareTo(endDate) == 0)
                    hl.CssClass = "changecolor";
    
                // add control to cell
                e.Cell.Controls.Add(hl);
            }
        }
    }
    

    Update Here is the output with the new code behind.

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SharePoint calendar control with multi day events: Calendar http://1.bp.blogspot.com/_8yYCvwdJans/RuECTJE5OmI/AAAAAAAAACc/iEqKLxyaZ9I/s1600-h/5.PNG http://1.bp.blogspot.com/_8yYCvwdJans/RuECTJE5OmI/AAAAAAAAACc/iEqKLxyaZ9I/s1600-h/5.PNG Here, the
In one of our project, we would like to have a calendar control that
I have an ASP.Net Calendar control that, on DayRender, loops through a list of
I have a composite drop down calendar user control that consists of a textbox
Can the calendar control be customsised so that, say you have a system of
I have an asp.net calendar control that is used to select a date and
I have a Calendar control on a VB6 form which on one machine is
We have a ASP.Net Calendar control, and in the DayRender event, we have the
I have a databound calendar control that loads the date from the database. The
I have an ASP.Net web user control that contains a TextBox and a calendar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.