Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello,



This is what I would like:
C#
void DayRender(Object source, DayRenderEventArgs e) 
      {
if ((e.Day.Date <= ArrivalDate.AddDays(_Notice)) 
            || (e.Day.Date >= Convert.ToDateTime("20/May/2016")) && (e.Day.Date <=              Convert.ToDateTime("25/May/2016"))
            || (e.Day.Date >= Convert.ToDateTime("1/June/2016")) && (e.Day.Date <= Convert.ToDateTime("05/June/2016")))
        {
            e.Day.IsSelectable = false;
            e.Cell.Font.Strikeout = true;
            e.Cell.BackColor = System.Drawing.Color.Aqua;
        }
}


However I have reached here and I am now stuck.
The date values are coming to the reader from a database.

C#
void DayRender(Object source, DayRenderEventArgs e) 
      {
       using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        connection.Open();

        SqlCommand command = new SqlCommand(queryString, connection);
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
           
        }
    }
}


What I have tried:

C#
using (SqlConnection connection = new SqlConnection(
           connectionString))
{
    connection.Open();
 
    SqlCommand command = new SqlCommand(queryString, connection);
    SqlDataReader reader = command.ExecuteReader();
    while (reader.Read())
    {
 
    }
}
Posted
Updated 8-May-16 22:27pm
v3
Comments
Philippe Mori 7-May-16 15:37pm    
Put code in what I have tried in a code block. Don't repeat the same thing in that section.

Don't write hard-coded values in code and don't convert constant from strings if you don't need to. Well, learn good coding practice.
FISH786 7-May-16 15:56pm    
thank you. that worked.
Sergey Alexandrovich Kryukov 7-May-16 15:38pm    
Any questions?
—SA
Karthik_Mahalingam 7-May-16 22:39pm    
Get the values from reader and replace it with the hardcoded values.

1 solution

try this...................
C#
// We need this namespace
using System.Drawing;
 
public partial class DefaultCS : System.Web.UI.Page
{
  protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
  {
    // Select all dates in the past
    if (e.Day.Date < System.DateTime.Today)
    {           
      // Disable date
      e.Day.IsSelectable = false;
      // Change color of disabled date
      e.Cell.ForeColor = Color.Gray;
    } 
 
  }
}


2.solution

"ASP.NET">ASPX
<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"> </asp:Calendar>

CodeBehind
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
  {
       if (e.Day.Date.CompareTo(DateTime.Today) < 0)
      {
          e.Day.IsSelectable = false;
      }
   }
 
Share this answer
 
v3
Comments
Member 11652153 9-May-16 4:39am    
it is helpful or Not

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