In this blog we will know how to find the booked dates records in the calendar control highlighted with different colors.
Scenario
Here the user is allowed to book the Marriage hall (Booked with Lawn/Booked without Lawn) according to his/her choice.After entering the data he/she can check it by using a calendar control according to his/her choice and then the respective day is booked with given condition with the provided conditions(Booked with Lawn/Booked without Lawn).
Booked with Lawn will be highlighted with green color.
Booked without Lawn will be highlighted with red color.
Insertbookdate.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Insertbookdate.aspx.cs" Inherits="mandap_book.Insertbookdate" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Book date[mm/dd/yyyy]"
Width="150px" BackColor="#FF9900" BorderColor="Yellow" ForeColor="Red"></asp:Label>
<asp:TextBox ID="txt_date" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Choose Occasion Type" Width="150px"
BackColor="#CC3300"></asp:Label>
<asp:DropDownList ID="DropDown_occasion" runat="server">
</asp:DropDownList>
</div>
<asp:Button ID="btn_insert" runat="server" onclick="btn_insert_Click"
Text="Insert" />
<asp:Label ID="lblmsg" runat="server" Text=""></asp:Label><br />
<asp:Button ID="btn_show" runat="server" Text="Show" onclick="btn_show_Click" />
</form>
</body>
</html>
Insertbookdate.aspx.cs code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace mandap_book
{
public partial class Insertbookdate : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand
com;
protected void Page_Load(object sender, EventArgs e)
{if (!IsPostBack)
{
DropDown_occasion.Items.Add("Choose Occasiontype");
DropDown_occasion.Items.Add("Booked with Lawn");
DropDown_occasion.Items.Add("Booked without Lawn");
}
}
protected void btn_insert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into test values(@ForDate,@Occasiontype)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@ForDate", txt_date.Text);
com.Parameters.AddWithValue("@Occasiontype", DropDown_occasion.SelectedValue);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
}
protected void btn_show_Click(object sender, EventArgs e)
{Response.Redirect("Default.aspx");
}
}
}
Default.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="mandap_book._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>

Join the conversation! Your thoughts help the community grow.