.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Calendar Control for Textbox in GridView

Posted By: Sajid P K     Posted Date: October 18, 2010    Points:2   Category :ASP.Net
Hi, I have a requirement for one of my project. I need to bind a Calendar Control to a Text box inside GridView.

1. In the Edit Mode i should see a textbox and a calendar control adjacent to it.
2. After selecting the date in the calendar, it should be displayed in the TextBox.
3. On clicking Update, i should be able to update the DB with the selected date.
I see that there is no DataField property for the TemplateField Column.

Please let me know if you have any solution.

Responses
Author: Clintonzz             
Posted Date: March 05, 2014     Points: 20   

Don't know if some UI calendar control would be helpful or not:

http://www.kettic.com/winforms_ui/calendar_overview.shtml

Author: K00898             
Posted Date: February 03, 2016     Points: 20   

Hi Sajid P K, I am currently wanting to implement the same thing as what you have mentioned in this thread. I wonder if you have found the solution? I am in a hurry. Can you let me know if you have a solution?

I have tried to do editing, deleting and inserting in gridview c# by the codes below, but to no avail:


%@ Page Title="" Language="C#" MaintainScrollPositionOnPostback="true" OnSelectionChanged="addCalendar1_SelectionChanged" OnSelectionChanged="Calendar1_SelectionChanged" OnSelectionChanged="addCalendar2_SelectionChanged" MasterPageFile="~/masterPage.Master" AutoEventWireup="true" CodeBehind="administrateProfileMaintenance.aspx.cs" Inherits="Sports_Booking_System.administrateProfileMaintenance" %>

<asp:TemplateField HeaderText="birthDate" SortExpression="birthDate">
<EditItemTemplate>
<br />
<asp:TextBox ID="calTextbox1" runat="server" Height="21px" Width="81px"
Text='<%# Eval("birthDate") %>'></asp:TextBox>
<asp:Calendar ID="Calendar2" runat="server" OnSelectionChanged="true" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="10px"
SelectedDate='<%# Eval("birthDate") %>' ShowGridLines="True"
VisibleDate='<%# Eval("birthDate") %>' Width="10px">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
<asp:CustomValidator ID="validateBirthDate" runat="server" ErrorMessage="* A date is required."
ValidationGroup="validate1" ></asp:CustomValidator>
</EditItemTemplate>
<ItemTemplate>
<br />
<asp:TextBox ID="calTextbox2" runat="server" Height="21px" Width="81px"
Text='<%# Eval("birthDate") %>'></asp:TextBox>
<asp:Calendar ID="Calendar1" OnSelectionChanged="true" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Enabled="False" Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399"
Height="10px" SelectedDate='<%# Eval("birthDate") %>' ShowGridLines="True"
VisibleDate='<%# Eval("birthDate") %>' Width="10px">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
</ItemTemplate>
<FooterTemplate>
<br />
<asp:TextBox ID="caltextbox3" runat="server" Height="21px" Width="81px"></asp:TextBox>
<asp:Calendar ID="addCalendar1" runat="server" onSelectionChanged="true" BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399"
Height="10px" ShowGridLines="True" Width="10px">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
<asp:RequiredFieldValidator ID="validateCalendarInFooter" runat="server"
ErrorMessage="Date is required."
ControlToValidate="caltextbox3" Text="*Date is required." ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>



protected void addCalendar1_SelectionChanged(object sender, EventArgs e)
{
caltextbox3.Text = addCalendar1_SelectionChanged.SelectedDate.ToShortDateString();
caltextbox2.Text = Calendar1_SelectionChanged.SelectedDate.ToShortDateString();
caltextbox1.Text = Calendar2_SelectionChanged.SelectedDate.ToShortDateString();

}


protected void Add1_Click(object sender, EventArgs e)
{
AccessDataSource1.InsertParameters["birthDate"].DefaultValue = ((Calendar)GridView1.FooterRow.FindControl("addBirthDate1"));
}





Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend