Try like this..
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="100%" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText=" Candidate name">
<ItemTemplate>
<asp:RadioButtonList ID="rdb" runat="server">
<asp:ListItem Text="Yes" />
<asp:ListItem Text="No" />
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Date Of Joining" DataField="JoiningDate" />
</Columns>
</asp:GridView>
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace POC
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("JoiningDate", typeof(DateTime));
dt.Rows.Add(DateTime.Now.AddYears(-6));
dt.Rows.Add(DateTime.Now.AddYears(-4));
dt.Rows.Add(DateTime.Now.AddYears(-76));
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var joiningDate = (DateTime)DataBinder.Eval(e.Row.DataItem, "JoiningDate");
RadioButtonList rdb = e.Row.FindControl("rdb") as RadioButtonList;
rdb.SelectedIndex = 1;
if ((DateTime.Now - joiningDate).TotalDays >= 1825)
{
e.Row.BackColor = System.Drawing.Color.Green;
rdb.SelectedIndex = 0;
}
}
}
}
}