---
title: "ajax calendar for textbox in gridview"  
description: "ajax calendar for textbox in gridview"  
author: "pramod niralakeri"  
published: 2015-03-05  
updated: 2015-03-09  
canonical: https://www.mindstick.com/forum/13004/ajax-calendar-for-textbox-in-gridview  
category: ".net"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# ajax calendar for textbox in gridview

i need solution for... [AJAX](https://www.mindstick.com/articles/1541/check-availability-of-user-name-or-email-using-asp-dot-net-ajax-and-jquery) [calendar](https://www.mindstick.com/articles/13088/how-to-choose-the-best-calendar-for-you-dynamics-crm-system) for [Textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) in [dynamic](https://www.mindstick.com/blog/11080/features-of-java-dynamic-complied-and-interpreted) [datagridView](https://www.mindstick.com/articles/607/working-with-datagridview-in-vc-sharp) where any number of textboxes can be created... but i need AJAX calendar with [validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework) like [date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner) should be within 5 from the today's date\
and [unique](https://www.mindstick.com/blog/12870/how-to-be-unique-in-business) date in each textbox i [mean](https://yourviews.mindstick.com/view/80768/what-does-real-minority-mean) no date should clash with textbox with any other\

## Replies

### Reply by Anonymous User

you can try this code\
\
**Default.aspx**\

```
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %> <!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></title></head><body>    <form id="form1" runat="server">    <div>        <asp:ScriptManager ID="ScriptManager1" runat="server">        </asp:ScriptManager>        <br />        <br />        <table width="800px" align="center">            <tr>                <td colspan="2" align="center">                    <b>Employee Details</b>                </td>            </tr>            <tr>                <td colspan="2">                    <asp:GridView ID="gvEmployeeDetails" runat="server" Width="100%" AutoGenerateColumns="false"                        ShowFooter="true" OnRowCommand="gvEmployeeDetails_RowCommand" OnRowDeleting="gvEmployeeDetails_RowDeleting"                        OnRowUpdating="gvEmployeeDetails_RowUpdating" OnRowCancelingEdit="gvEmployeeDetails_RowCancelingEdit"                        OnRowEditing="gvEmployeeDetails_RowEditing">                        <Columns>                            <asp:TemplateField HeaderText="Employee ID">                                <ItemTemplate>                                    <asp:Label ID="lblEmpID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "id") %>'></asp:Label>                                </ItemTemplate>                                <EditItemTemplate>                                    <asp:Label ID="lblEditEmpID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "id") %>'></asp:Label>                                </EditItemTemplate>                                <FooterTemplate>                                    <asp:TextBox ID="txtAddEmpID" runat="server"></asp:TextBox>                                </FooterTemplate>                            </asp:TemplateField>                            <asp:TemplateField HeaderText="Name">                                <ItemTemplate>                                    <asp:Label ID="lblName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "name") %>'></asp:Label>                                </ItemTemplate>                                <EditItemTemplate>                                    <asp:TextBox ID="txtEditName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "name") %>'></asp:TextBox>                                </EditItemTemplate>                                <FooterTemplate>                                    <asp:TextBox ID="txtAddName" runat="server"></asp:TextBox>                                </FooterTemplate>                            </asp:TemplateField>                            <asp:TemplateField HeaderText="City">                                <ItemTemplate>                                    <asp:Label ID="lblCity" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "city") %>'></asp:Label>                                </ItemTemplate>                                <EditItemTemplate>                                    <asp:TextBox ID="txtEditCity" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "city") %>'></asp:TextBox>                                </EditItemTemplate>                                <FooterTemplate>                                    <asp:TextBox ID="txtAddCity" runat="server"></asp:TextBox>                                </FooterTemplate>                            </asp:TemplateField>                            <asp:TemplateField HeaderText="Date of Joining">                                <ItemTemplate>                                    <asp:Label ID="lblCountry" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "City") %>'></asp:Label>                                </ItemTemplate>                                <EditItemTemplate>                                    <asp:TextBox ID="txtEditCountry" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "City") %>'></asp:TextBox>                                    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtEditCountry"                                                         
PopupButtonID="txtEditCountry" Format="dd/MM/yyyy">                                    </asp:CalendarExtender>                                </EditItemTemplate>                                <FooterTemplate>                                    <asp:TextBox ID="txtAddCountry" runat="server"></asp:TextBox>                                     <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtAddCountry"                                                          
PopupButtonID="txtAddCountry" Format="dd/MM/yyyy">                                    </asp:CalendarExtender>                                </FooterTemplate>                            </asp:TemplateField>                            <asp:TemplateField HeaderText="Action">                                <ItemTemplate>                                    <asp:ImageButton ID="imgbtnEdit" runat="server" CommandName="Edit" ImageUrl="~/Images/icon-edit.png"                                        Height="32px" Width="32px" />                                    <asp:ImageButton ID="imgbtnDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/Delete.png" />                                </ItemTemplate>                                <EditItemTemplate>                                    <asp:ImageButton ID="imgbtnUpdate" runat="server" CommandName="Update" ImageUrl="~/Images/icon-update.png" />                                    <asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Images/icon-Cancel.png" />                                </EditItemTemplate>                                <FooterTemplate>                                    <asp:LinkButton ID="lbtnAdd" runat="server" CommandName="ADD" Text="Add" Width="100px"></asp:LinkButton>                                </FooterTemplate>                            </asp:TemplateField>                        </Columns>                    </asp:GridView>                </td>            </tr>            <tr>                <td colspan="2" style="background-image: url(Images/header.jpg); height: 30px">                </td>            </tr>        </table>    </div>    </form></body></html>
```

**default.aspx.cs**\
\

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Xml;using System.Data;using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page{     SqlConnection conn = new SqlConnection("Data
Source=local;Initial Catalog=MyDB;user
id=sa;password=xyz;MultipleActiveResultSets=True;");    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            BindData();        }    }     protected void BindData()    {        DataSet ds = new DataSet();        DataTable FromTable = new DataTable();        conn.Open();        string cmdstr = "Select *
from Employee";        SqlCommand cmd = new SqlCommand(cmdstr, conn);        SqlDataAdapter adp = new SqlDataAdapter(cmd);        adp.Fill(ds);        cmd.ExecuteNonQuery();        FromTable = ds.Tables[0];        if (FromTable.Rows.Count > 0)        {            gvEmployeeDetails.DataSource =
FromTable;            gvEmployeeDetails.DataBind();        }        else        {           
FromTable.Rows.Add(FromTable.NewRow());            gvEmployeeDetails.DataSource =
FromTable;            gvEmployeeDetails.DataBind();            int TotalColumns = gvEmployeeDetails.Rows[0].Cells.Count;           
gvEmployeeDetails.Rows[0].Cells.Clear();            gvEmployeeDetails.Rows[0].Cells.Add(new TableCell());           
gvEmployeeDetails.Rows[0].Cells[0].ColumnSpan = TotalColumns;           
gvEmployeeDetails.Rows[0].Cells[0].Text = "No
records Found";        }        ds.Dispose();        conn.Close();    }     protected void gvEmployeeDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)    {        Label lblEmpID = (Label)gvEmployeeDetails.Rows[e.RowIndex].FindControl("lblEmpID");         conn.Open();        string cmdstr = "delete from
Employee where id=@empid";        SqlCommand cmd = new SqlCommand(cmdstr, conn);        cmd.Parameters.AddWithValue("@empid",
lblEmpID.Text);        cmd.ExecuteNonQuery();        conn.Close();        BindData();     }    protected void gvEmployeeDetails_RowCommand(object sender, GridViewCommandEventArgs
e)    {        if (e.CommandName.Equals("ADD"))        {            TextBox txtAddEmpID = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtAddEmpID");            TextBox txtAddName = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtAddName");            TextBox txtAddDesignation = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtAddDesignation");            TextBox txtAddCity = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtAddCity");            TextBox txtAddCountry = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtAddCountry");             conn.Open();            string cmdstr = "insert into
Employee(empid,name,designation,city,dateofjoin) values(@empid,@name,@designation,@city,@dateofjoin)";            SqlCommand cmd = new SqlCommand(cmdstr, conn);            cmd.Parameters.AddWithValue("@empid",
txtAddEmpID.Text);            cmd.Parameters.AddWithValue("@name",
txtAddName.Text);            cmd.Parameters.AddWithValue("@designation",
txtAddDesignation.Text);            cmd.Parameters.AddWithValue("@city",
txtAddCity.Text);            cmd.Parameters.AddWithValue("@dateofjoin",
txtAddCountry.Text);            cmd.ExecuteNonQuery();            conn.Close();            BindData();        }    }    protected void gvEmployeeDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)    {        Label lblEditEmpID = (Label)gvEmployeeDetails.Rows[e.RowIndex].FindControl("lblEditEmpID");        TextBox txtEditName = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txtEditName");        TextBox txtEditDesignation = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txtEditDesignation");        TextBox txtEditCity = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txtEditCity");        TextBox txtEditCountry = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txtEditCountry");         conn.Open();        string cmdstr = "update Employee set name=@name,designation=@designation,city=@city,dateofjoin=@dateofjoin
where empid=@empid";        SqlCommand cmd = new SqlCommand(cmdstr, conn);        cmd.Parameters.AddWithValue("@empid",lblEditEmpID.Text);        cmd.Parameters.AddWithValue("@name",txtEditName.Text);        cmd.Parameters.AddWithValue("@designation",txtEditDesignation.Text);        cmd.Parameters.AddWithValue("@city",txtEditCity.Text);        cmd.Parameters.AddWithValue("@dateofjoin",txtEditCountry.Text);        cmd.ExecuteNonQuery();        conn.Close();         gvEmployeeDetails.EditIndex = -1;        BindData();     }    protected void gvEmployeeDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs
e)    {        gvEmployeeDetails.EditIndex = -1;        BindData();    }    protected void gvEmployeeDetails_RowEditing(object sender, GridViewEditEventArgs e)    {        gvEmployeeDetails.EditIndex =e.NewEditIndex;        BindData();    }}
```

**Output:**\

![ajax calendar for textbox in gridview](https://www.mindstick.com/mindstickforums/e710eeff-22ed-4622-b1d0-eac726cc5181/images/1174bbf6-092a-4784-8dea-48e041fc3580.png)


---

Original Source: https://www.mindstick.com/forum/13004/ajax-calendar-for-textbox-in-gridview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
