Hi sambath,
Please refer below sample.
HTML
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#333333" gridline="none" HeaderStyle-ForeColor="White"
CssClass="gridviewtable" HeaderStyle-Height="40px" RowStyle-Height="40px" AlternatingRowStyle-BackColor="#F5F5F5"
runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView_OnRowDataBound"
EnableViewState="true" DataKeyNames="RegistrationID">
<Columns>
<asp:TemplateField HeaderText="S.No" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle Width="32px" />
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="RegistrationID" ItemStyle-HorizontalAlign="Center" HeaderText="Reg.ID" />
<asp:BoundField DataField="Patient_ID" ItemStyle-HorizontalAlign="Center" HeaderText="Patient ID" />
<asp:BoundField DataField="P_Name" ItemStyle-HorizontalAlign="Center" HeaderText="Name" />
<asp:BoundField DataField="Gender" ItemStyle-HorizontalAlign="Center" HeaderText="Gender" />
<asp:BoundField DataField="age" ItemStyle-HorizontalAlign="Center" HeaderText="Age" />
<asp:TemplateField ItemStyle-Width="150px" HeaderText="Address">
<ItemTemplate>
<asp:Label ID="lblAddress" runat="server" Text='<%# Eval("address")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="90px" HeaderText="Contact No.">
<ItemTemplate>
<asp:Label ID="lblContactno" runat="server" Text='<%# Eval("mobile") +" / "+ Eval("altmobile")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RefDoctor" ItemStyle-HorizontalAlign="Center" HeaderText="Ref Doctor" />
<asp:BoundField DataField="AppDated" ItemStyle-HorizontalAlign="Center" HeaderText="Appoinment Date" />
<asp:BoundField DataField="CaseAtten" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Size="Larger"
ItemStyle-Font-Bold="true" HeaderText="Case Status" />
<asp:TemplateField HeaderText="Payment">
<ItemTemplate>
<asp:LinkButton ID="lnkViewDetails" runat="server" CssClass="btn-sm" CommandArgument='<%# Eval("RegistrationID")%>'
OnClick="ViewDetails" Text="Payment" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Payment History">
<ItemTemplate>
<asp:LinkButton ID="lnkpayhistory" Text="Payment History" CssClass="btn-sm" OnClick="lnkpayhistory_Click"
runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Existing" HeaderText="Existing" Visible="false" />
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:LinkButton ID="lnkeditnew" OnClick="lnkeditnew_Click" ToolTip="Edit" CssClass="fa fa-edit"
runat="server"> </asp:LinkButton>
<asp:LinkButton ID="lnkcanapp" Text="" ToolTip="Cancel Appointment" CssClass="fa fa-trash"
OnClick="lnkcanapp_Click" runat="server"> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
VB.Net
Imports 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("RegistrationID", typeof(string)),
new DataColumn("Patient_ID", typeof(string)),
new DataColumn("P_Name",typeof(string)),
new DataColumn("Gender",typeof(string)),
new DataColumn("age",typeof(string)),
new DataColumn("address",typeof(string)),
new DataColumn("city",typeof(string)),
new DataColumn("pincode",typeof(string)),
new DataColumn("mobile",typeof(string)),
new DataColumn("altmobile",typeof(string)),
new DataColumn("RefDoctor",typeof(string)),
new DataColumn("AppDated",typeof(DateTime)),
new DataColumn("CaseAtten",typeof(string)),
new DataColumn("Existing",typeof(string)) });
dt.Rows.Add("r1", "p1", "John Hammond", "Male", "35", "United States", "New Jercy", "4165465", "1555456546", "5868765468", "dr.A", "1/02/2017", "Attend", "E1");
dt.Rows.Add("r2", "p2", "Mudassar Khan", "Male", "30", "India", "400097", "Mumbai", "548985878", "8794568542", "dr.B", "1/05/2017", "Attend", "E2");
dt.Rows.Add("r3", "p3", "Suzanne Mathews", "Male", "38", "France", "459097", "Tokyo", "8974568522", "012354879623", "dr.C", DateTime.Now, "Not Attend", "E3");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void lnkeditnew_Click(object sender, EventArgs e)
{
}
protected void lnkcanapp_Click(object sender, EventArgs e)
{
}
protected void lnkpayhistory_Click(object sender, EventArgs e)
{
}
protected void ViewDetails(object sender, EventArgs e)
{
}
protected void GridView_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime appDate = Convert.ToDateTime(e.Row.Cells[9].Text);
LinkButton lbEdit = e.Row.FindControl("lnkeditnew") as LinkButton;
if (appDate.ToString("dd/MM/yyyy") == DateTime.Now.ToString("dd/MM/yyyy"))
{
lbEdit.Enabled = false;
}
else
{
lbEdit.Enabled = true;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("RegistrationID", GetType(String)), New DataColumn("Patient_ID", GetType(String)), New DataColumn("P_Name", GetType(String)), New DataColumn("Gender", GetType(String)), New DataColumn("age", GetType(String)), New DataColumn("address", GetType(String)), New DataColumn("city", GetType(String)), New DataColumn("pincode", GetType(String)), New DataColumn("mobile", GetType(String)), New DataColumn("altmobile", GetType(String)), New DataColumn("RefDoctor", GetType(String)), New DataColumn("AppDated", GetType(DateTime)), New DataColumn("CaseAtten", GetType(String)), New DataColumn("Existing", GetType(String))})
dt.Rows.Add("r1", "p1", "John Hammond", "Male", "35", "United States", "New Jercy", "4165465", "1555456546", "5868765468", "dr.A", "1/02/2017", "Attend", "E1")
dt.Rows.Add("r2", "p2", "Mudassar Khan", "Male", "30", "India", "400097", "Mumbai", "548985878", "8794568542", "dr.B", "1/05/2017", "Attend", "E2")
dt.Rows.Add("r3", "p3", "Suzanne Mathews", "Male", "38", "France", "459097", "Tokyo", "8974568522", "012354879623", "dr.C", DateTime.Now, "Not Attend", "E3")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub lnkeditnew_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub lnkcanapp_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub lnkpayhistory_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ViewDetails(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub GridView_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim appDate As DateTime = Convert.ToDateTime(e.Row.Cells(9).Text)
Dim lbEdit As LinkButton = TryCast(e.Row.FindControl("lnkeditnew"), LinkButton)
If appDate.ToString("dd/MM/yyyy") = DateTime.Now.ToString("dd/MM/yyyy") Then
lbEdit.Enabled = False
Else
lbEdit.Enabled = True
End If
End If
End Sub
Screenshot