How to check if startdate and enddate overlaps when changing date in datetimecontrol? (C# or SHAREPOINT)pls.
is there anyone who knows how to check if dates are overlapping?
this is my gridview:
| ID | cost | start date | end date | status |
---------------------------------------------
| 1 | 66.00| 11/02/13 | 11/20/13 | active | =no overlap
| 2 | 12.00| 11/21/13 | 11/30/13 | active | =no overlap
| 3 | 67.00| 11/28/13 | 12/10/13 | active | =overlap
---------------------------------------------
|____|______|____________|__________|________| =new row
---------------------------------------------
|Add|
|SAVE|=insert/update data to sql database
i have a gridview and 2 button(save and add),add button it will add a new row. when i change date in startdate and enddate it will need to check the gridview if it will overlap other dates. if overlaps it will throw an error message. i dont know what to do..so please help me. :)
this are the info about the itemtemplate in my gridview:
ID= textbox
Cost= textbox
start date= datetimecontrol
end date= datetimecontrol
status= dropdownlist
:)
this is my code in startdate and enddate when datechanged:
protected void date_issued_DateChanged(object sender, EventArgs e)
{
DateTime tbdate = (DateTime) sender;
for (int i = 0; i < gvw.Rows.Count; i++)
{
//DateTimeControl sd = (DateTimeControl)gvw.Rows[i].Cells[2].FindControl("date_issued");
DateTime newdtissued = new DateTime();
DateTime dtissued;
DateTime dexp;
if (DateTime.TryParse(tbdate.ToString(), out newdtissued))
{
foreach (GridViewRow row in gvw.Rows)
{
if ((DateTime.TryParse(maDDL.getControlValue("date_issued", row), out dtissued)) &&
(DateTime.TryParse(maDDL.getControlValue("expiration_date", row), out dexp)))
{
if (dtissued <= dexp && dexp >= dtissued)
{
string msg = string.Empty;
msg = "Date OverLaps!";
ShowMessage(msg);
//sd.Focus();
}
else
{
string msg = string.Empty;
msg = "else 2nd";
ShowMessage(dtissued.ToString());
}
}
}
}
else
{
string msg = string.Empty;
msg = "else 1st";
ShowMessage(msg);
}
}
}
in this code i get an error (Specified cast is not valid.)
pls..help me and check my code :)
thanks in advance. ...