views:

39

answers:

2

Hi all i have designed a gridview in that one of my template field will be like

 <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="lblTrialPeriodEnds" runat="server" Text='<%# Eval("trialPeriodEnds","{0:dd/MM/yyyy}") %>'
                            Width="61px"></asp:Label>
                    </ItemTemplate>
                    <HeaderTemplate>
                        TrialPeriodEnds
                    </HeaderTemplate>
<EditItemTemplate>
   <asp:TextBox Id="txtRenew" runat="server" Text='<%# Eval("trialPeriodEnds","{0:dd/MM/yyyy}") %>'
                            Width="61px" />
</EditItemTemplate>
                </asp:TemplateField>

Now what i need is i will have a pop up calendar after the text box when i click on edit . If i select a date greater than the date existed in the text box i would like to set my Database field to Yes..

ANy idea please....

+1  A: 

You can convert text from text box into DateTime object and use DateTime class methods or just subtract two DateTime objects which will give you TimeSpan objects. Then you can compare dates as per your requirements.

Shekhar
Means initially i have to store my date value in to a string and then i should compare right..
Dorababu
@Dorababu . Yes, initially you have to store text into a string.For Example,string dateString = txtDate.Text;DateTime time = DateTime.Parse(dateString);Note- you need to add exception handling code because if Parse() method fails, it will throw exception.
Shekhar
A: 

Assumming the popup is using client side scripting and not causing a post back. Here is a quick solution to your question.
1. Add a hidden field to your page. Make sure you include runat="server" so you can access it in your code behind.

2.Create a function that will be called whenever the Calendar Date is clicked

Function CompareDate(str CalendarDate)
{
 var Date1 = new Date($("txtRenew").Text); 
 var Date2 = new Date(CalendarDate); 

 if (Date2 > Date1)
 {
     $("#hdnValue").value = "Yes";
 }
 else
 {
     $("#hdnValue").value = "No";
 }
}

3. Retrieve hdnValue from code behind.

The calendar should have a DateChanged Event that you can add this function too.

Jordan Johnson