Hi vail,
Refer the below sample. I have not tested the code. So you need to implement and test the code.
For showing popup i have used the below article.
Here i have used timer to refresh the gridview in every 1 hour to check the expiry date. Now the code executed as per your condition.
So you need to change the code as per your requirement.
HTML
<div>
<asp:ScriptManager runat="server" />
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000">
</asp:Timer>
<asp:GridView runat="server" ID="gvDocuments" AutoGenerateColumns="false" OnRowDataBound="gvDocuments_RowDataBound">
<Columns>
<asp:BoundField DataField="DocumentID" HeaderText="ID" />
<asp:BoundField DataField="DocumentName" HeaderText="Name" />
<asp:BoundField DataField="DocumentExpiryDate" HeaderText="Expiry Date" />
</Columns>
</asp:GridView>
<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mpe" runat="server"
PopupControlID="pnlPopup" TargetControlID="lnkDummy" BackgroundCssClass="modalBackground"
CancelControlID="btnHide">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Modal Popup
</div>
<div class="body">
<asp:Panel runat="server" ID="pnlStatus">
</asp:Panel>
<br />
<asp:Button ID="btnHide" runat="server" Text="Hide Modal Popup" />
</div>
</asp:Panel>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("DocumentID", typeof(int)), new DataColumn("DocumentName"), new DataColumn("DocumentExpiryDate") });
dt.Rows.Add(1, "Test1.doc", "10/1/2017");
gvDocuments.DataSource = dt;
gvDocuments.DataBind();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Timer1.Interval = ((1000 * 60) * 60); //1 Hour
BindGrid();
}
protected void gvDocuments_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = new Label();
DataTable expiredDocuments = new DataTable();
expiredDocuments.Columns.AddRange(new DataColumn[3] { new DataColumn("DocumentID", typeof(int)), new DataColumn("DocumentName"), new DataColumn("DocumentExpiryDate") });
DateTime expiryDate = Convert.ToDateTime(e.Row.Cells[2].Text);
DateTime currentDate = DateTime.Now;
if (Convert.ToDateTime(currentDate.ToShortDateString()) <= Convert.ToDateTime(expiryDate.AddMonths(-3).ToShortDateString()))
{
lbl.Text = "Document expires after 3 months";
lbl.ForeColor = System.Drawing.Color.Yellow;
pnlStatus.Controls.Add(lbl);
ModalPopupExtender1.Show();
}
else if (Convert.ToDateTime(currentDate.ToShortDateString()) <= Convert.ToDateTime(expiryDate.AddMonths(-2).ToShortDateString()))
{
lbl.Text = "Document expires after 2 months";
lbl.ForeColor = System.Drawing.Color.Orange;
pnlStatus.Controls.Add(lbl);
ModalPopupExtender1.Show();
}
else if (Convert.ToDateTime(currentDate.ToShortDateString()) <= Convert.ToDateTime(expiryDate.AddMonths(-1).ToShortDateString()))
{
lbl.Text = "Document expires after 1 months";
lbl.ForeColor = System.Drawing.Color.Red;
pnlStatus.Controls.Add(lbl);
ModalPopupExtender1.Show();
}
}
}