Dear Sir,
please help me to do this
BG Issued Date <=30day than BG Expiring Date column color is red how to do this
.aspx
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#99ccff" HeaderStyle-ForeColor="black" DataKeyNames="Id"
runat="server" Font-Size="small" AutoGenerateColumns="False" HeaderStyle-Font-Size="16px" OnRowCommand="GridView1_RowCommand"
OnRowDataBoub="GridView1_RowDataBound" EmptyDataText="There are no any BGMS pending.." Height="100px" Width="1900px"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDataBound="GridView1_RowDataBound"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
CssClass="auto-style56" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<Columns>
<asp:BoundField DataField="Id" HeaderText="BGMS id" />
<asp:BoundField DataField="emp_id" HeaderText="Emp. id" />
<asp:BoundField DataField="agncy_nm" HeaderText="Agency Name " />
<asp:BoundField DataField="bg_typ" HeaderText="Type of BG" />
<asp:BoundField DataField="nit_no" HeaderText="NIT No" />
<asp:BoundField DataField="po_no" HeaderText="PO No" />
<asp:BoundField DataField="bg_no" HeaderText="BG No" />
<asp:BoundField DataField="bg_issue_dt" DataFormatString="{0:dd-MM-yyyy}" HeaderText="BG Issued Date" />
<asp:TemplateField HeaderText="BG Expiring Date">
<ItemTemplate>
<asp:Label ID="lblDate" Text='<%# Eval("bg_exp_dt") %>' runat="server" />
</ItemTemplate>
<ItemStyle Width="200px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="bg_issu_bnk" HeaderText="BG Issuing Bank" />
<asp:BoundField DataField="bg_rcv_midia" HeaderText="BG Received Media" />
<asp:BoundField DataField="frst_rcv_whom" HeaderText="1st Received by whom" />
<asp:BoundField DataField="bg_hnd_ovr" HeaderText="BG Handed Over to" />
<asp:BoundField DataField="schdle_dt" HeaderText="Scheduled Del Dt" />
<asp:BoundField DataField="fnl_dlvry_dt" HeaderText="Date of Final Delivery" />
<asp:BoundField DataField="is_prtl_dlvry" HeaderText="Is Partial Delivery" />
<asp:BoundField DataField="prcnt_dlvry" HeaderText="% Delivered" />
<asp:BoundField DataField="prtl_dlvry_dt" HeaderText="Partial Delivery date" />
<asp:BoundField DataField="actn_pnding" HeaderText="Action Pending" />
<asp:BoundField DataField="released" HeaderText="BG Released" />
<asp:BoundField DataField="bg_closed" HeaderText="Closed" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Web.UI.HtmlControls;
using System.Drawing;
namespace BGMS
{
public partial class rprt : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.BindGrid();
}
private void BindGrid()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlDataAdapter sda = new SqlDataAdapter("SELECT Id,emp_id,agncy_nm, bg_typ, nit_no,po_no,bg_no,bg_issue_dt,bg_exp_dt,bg_issu_bnk,bg_rcv_midia,frst_rcv_whom,bg_hnd_ovr,actn_pnding,schdle_dt,prcnt_dlvry,fnl_dlvry_dt,image,Date,bg_closed,is_prtl_dlvry,prtl_dlvry_dt,released FROM bgms WHERE EMP_ID=" + Session["emp_id"] + "", con);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
{
}
protected void GridView1_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
}
protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != GridView1.EditIndex)
{
DateTime time = Convert.ToDateTime((e.Row.FindControl("lblDate") as Label).Text);
if (DateTime.Now.Subtract(time).TotalHours <= 30d)
{
(e.Row.FindControl("lblDate") as Label).ForeColor = Color.Black;
}
else
{
(e.Row.FindControl("lblDate") as Label).ForeColor = Color.Red;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[7].Font.Bold = true;
e.Row.Cells[8].Font.Bold = true;
}
}
protected void View(object sender, EventArgs e)
{
LinkButton lnkView = sender as LinkButton;
GridViewRow row = lnkView.NamingContainer as GridViewRow;
string urlName = Request.Url.AbsoluteUri;
// Removing the Page Name
urlName = urlName.Remove(urlName.LastIndexOf("/"));
//Adding FolderName and FileName in the URL
string url = string.Format("{0}/img/{1}", urlName, row.Cells[0].Text);
string script = "<script type='text/javascript'>window.open('" + url + "')</script>";
this.ClientScript.RegisterStartupScript(this.GetType(), "script", script);
}
}
}