How to check if start date and end date overlaps when adding or updating in gridview?
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 put a data in start date and end date 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. :) all itemtemplate in gridview are texboxes except ID and status. :)
this is my code in startdate and enddate textchanged:
protected void date_issued_TextChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in gvw.Rows)
{
DateTime dtissued = Convert.ToDateTime(maDDL.getControlValue("date_issued", row));
DateTime dexp = Convert.ToDateTime(maDDL.getControlValue("expiration_date", row));
if (dtissued <= dexp || dexp >= dtissued)
{
lblMsg.Text="Date OverLaps!";
}
}
}
protected void expiration_date_TextChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in gvw.Rows)
{
DateTime dtissued = Convert.ToDateTime(maDDL.getControlValue("date_issued", row));
DateTime dexp = Convert.ToDateTime(maDDL.getControlValue("expiration_date", row));
if (dtissued <= dexp || dexp >= dtissued)
{
lblMsg.Text = "Date OverLaps!";
}
}
}
pls..help me :)
thanks in advance. ...