How to compare the difference of date in gridview textbox
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 column to Yes..
Any idea please....
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.
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.
精彩评论