Hi indradeo,
Refer below sample.
HTML
<asp:GridView ID="gvDates" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Save">
<ItemTemplate>
<asp:Button ID="btnSave" Text="Save" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:Button ID="btnUpdate" Text="Update" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namesapace
C#
using System.Data;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Date") });
dt.Rows.Add("04/18/2023");
dt.Rows.Add("04/16/2023");
gvDates.DataSource = dt;
gvDates.DataBind();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime date = Convert.ToDateTime((e.Row.FindControl("lblDate") as Label).Text);
if (date.ToLongDateString() == DateTime.Now.ToLongDateString())
{
(e.Row.FindControl("btnSave") as Button).Visible = false;
(e.Row.FindControl("btnUpdate") as Button).Visible = true;
}
else
{
(e.Row.FindControl("btnSave") as Button).Visible = true;
(e.Row.FindControl("btnUpdate") as Button).Visible = false;
}
}
}
Screenshot