locked
Ajax Calendar RRS feed

  • Question

  • User1224235962 posted

    Hi All,

    I have created one data gird and in that third column is date, for which I am using Ajax Calendar.

    Now I have to disable the past date from the calendar which is appearing in Grid.

    Please suggest how to do that

    Wednesday, May 25, 2016 12:18 PM

Answers

  • User541108374 posted

    Hi,

    according to the properties at http://www.ajaxcontroltoolkit.net/Calendar/Calendar.aspx you can set the StartDate.

    For example:

    <asp:CalendarExtenderID="Calendar1"runat="server" 
        Enabled="True" TargetControlID="TextBox1"Format="dd/MM/yyyy" ></asp:CalendarExtender>

    And in code behind:

    protected void Page_Load(object sender, EventArgs e)
    {
       Calendar1.StartDate = DateTime.Now;
    }

    Start with this as a base point and adjust DateTime.Now to the date in that row in the appropriate grid event.

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 25, 2016 2:27 PM
  • User61956409 posted

    Hi Sandy1234,

    I have created one data gird and in that third column is date, for which I am using Ajax Calendar.

    Now I have to disable the past date from the calendar which is appearing in Grid.

    You could refer to the following sample code.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:TemplateField HeaderText="ID">
                <ItemTemplate>
                    <asp:Label ID="lblid" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <asp:Label ID="lblname" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Date">
                <ItemTemplate>
                    <asp:TextBox ID="txtdate" runat="server"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox txt = (TextBox)e.Row.FindControl("txtdate");
    
            CalendarExtender cld = new CalendarExtender();
            cld.TargetControlID = txt.ID;
    
            cld.StartDate = DateTime.Now;
    
            e.Row.Cells[2].Controls.Add(cld);
        }
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2016 3:30 AM

All replies

  • User541108374 posted

    Hi,

    according to the properties at http://www.ajaxcontroltoolkit.net/Calendar/Calendar.aspx you can set the StartDate.

    For example:

    <asp:CalendarExtenderID="Calendar1"runat="server" 
        Enabled="True" TargetControlID="TextBox1"Format="dd/MM/yyyy" ></asp:CalendarExtender>

    And in code behind:

    protected void Page_Load(object sender, EventArgs e)
    {
       Calendar1.StartDate = DateTime.Now;
    }

    Start with this as a base point and adjust DateTime.Now to the date in that row in the appropriate grid event.

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 25, 2016 2:27 PM
  • User61956409 posted

    Hi Sandy1234,

    I have created one data gird and in that third column is date, for which I am using Ajax Calendar.

    Now I have to disable the past date from the calendar which is appearing in Grid.

    You could refer to the following sample code.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:TemplateField HeaderText="ID">
                <ItemTemplate>
                    <asp:Label ID="lblid" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <asp:Label ID="lblname" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Date">
                <ItemTemplate>
                    <asp:TextBox ID="txtdate" runat="server"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox txt = (TextBox)e.Row.FindControl("txtdate");
    
            CalendarExtender cld = new CalendarExtender();
            cld.TargetControlID = txt.ID;
    
            cld.StartDate = DateTime.Now;
    
            e.Row.Cells[2].Controls.Add(cld);
        }
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2016 3:30 AM