Hi akhter,
Use Hyperlink instead of AnchorLink. Refer below sample.
HTML
<asp:GridView ID="GVballist" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="DID" HeaderText="DID" SortExpression="DID" />
<asp:TemplateField HeaderText="Dispatch No">
<ItemTemplate>
<asp:HyperLink ID="lnkUpdate" NavigateUrl='<%#String.Format("BBupdate.aspx?DID={0}", Eval("DID"))%>'
runat="server" Text='<%#Eval("DID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer">
<ItemTemplate>
<asp:Label ID="CustomerName" runat="server" Text='<%#Bind("CustomerName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="Date" runat="server" Text='<%#Bind("Date")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="Status" runat="server" Text='<%#Bind("Status")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("DID", typeof(int)),
new DataColumn("CustomerName", typeof(string)),
new DataColumn("Date",typeof(string)),
new DataColumn("Status",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "01/01/2019", "Close");
dt.Rows.Add(2, "Mudassar Khan", "01/01/2019", "Active");
dt.Rows.Add(3, "Suzanne Mathews", "01/01/2019", "Active");
dt.Rows.Add(4, "Robert Schidner", "01/01/2019", "Close");
GVballist.DataSource = dt;
GVballist.DataBind();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.FindControl("Status") as Label).Text.ToLower().Trim() == "close")
{
(e.Row.FindControl("lnkUpdate") as HyperLink).Enabled = false;
}
else
{
(e.Row.FindControl("lnkUpdate") as HyperLink).Enabled = true;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("DID", GetType(Integer)),
New DataColumn("CustomerName", GetType(String)),
New DataColumn("Date", GetType(String)),
New DataColumn("Status", GetType(String))})
dt.Rows.Add(1, "John Hammond", "01/01/2019", "Close")
dt.Rows.Add(2, "Mudassar Khan", "01/01/2019", "Active")
dt.Rows.Add(3, "Suzanne Mathews", "01/01/2019", "Active")
dt.Rows.Add(4, "Robert Schidner", "01/01/2019", "Close")
GVballist.DataSource = dt
GVballist.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If (TryCast(e.Row.FindControl("Status"), Label)).Text.ToLower().Trim() = "close" Then
TryCast(e.Row.FindControl("lnkUpdate"), HyperLink).Enabled = False
Else
TryCast(e.Row.FindControl("lnkUpdate"), HyperLink).Enabled = True
End If
End If
End Sub