Hi yogeshc,
I have created sample that full-fill your requirement. Refer the below sample.
HTML
<asp:GridView ID="GridView2" runat="server" CssClass="table table-striped table-hover"
DataKeyNames="student_Id" AutoGenerateColumns="false" GridLines="None" Width="50%"
OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField HeaderText="Admission No">
<ItemTemplate>
<asp:Label ID="lblExamstudent_Id" runat="server" Text='<%# Eval("student_Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Term">
<ItemTemplate>
<asp:Label ID="lblTerm" runat="server" Text='<%# Eval("Term") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:Label ID="lblexamAmount" runat="server" Text='<%# Eval("Amount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IsPaid">
<ItemTemplate>
<asp:Label ID="lblexamIsPaid" runat="server" Text='<%# getvalu2(Eval("IsPaid")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="date">
<ItemTemplate>
<asp:Label ID="lblexamdate" runat="server" Text='<%# Eval("date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pay">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEditexam" runat="server" Text="Pay Now" CssClass="btn btn-info"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
bindexamfee()
End If
End Sub
' Get this from database
Private Sub bindexamfee()
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("student_Id", GetType(Integer)), New DataColumn("Term", GetType(Integer)), New DataColumn("Amount", GetType(Integer)), New DataColumn("IsPaid", GetType([Boolean])), New DataColumn("date", GetType(String))})
dt.Rows.Add(10003, 1, 200, 1, "01/10/2017")
dt.Rows.Add(10003, 2, 200, 1, "02/10/2017")
dt.Rows.Add(10003, 3, 200, 0, "")
GridView2.DataSource = dt
GridView2.DataBind()
End Sub
Public Function getvalu2(objBit As Object) As String
If (Convert.ToInt32(objBit) = 1) Then
Return "Yes"
Else
Return "No"
End If
End Function
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim isPaid As String = TryCast(e.Row.FindControl("lblexamIsPaid"), Label).Text
If isPaid.ToUpper() = "YES" Then
TryCast(e.Row.FindControl("lnkBtnEditexam"), LinkButton).Visible = False
End If
End If
End Sub
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
bindexamfee();
}
}
// Get this from database.
private void bindexamfee()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("student_Id", typeof(int)),
new DataColumn("Term", typeof(int)),
new DataColumn("Amount",typeof(int)),
new DataColumn("IsPaid",typeof(Boolean)),
new DataColumn("date",typeof(string))
});
dt.Rows.Add(10003, 1, 200, 1, "01/10/2017");
dt.Rows.Add(10003, 2, 200, 1, "02/10/2017");
dt.Rows.Add(10003, 3, 200, 0, "");
GridView2.DataSource = dt;
GridView2.DataBind();
}
public string getvalu2(object objBit)
{
if ((Convert.ToInt32(objBit) == 1))
{
return "Yes";
}
else
{
return "No";
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string isPaid = (e.Row.FindControl("lblexamIsPaid") as Label).Text;
if (isPaid.ToUpper() == "YES")
{
(e.Row.FindControl("lnkBtnEditexam") as LinkButton).Visible = false;
}
}
}
Screenshot
If you don't want to use rowdatabound then you can do it using IF ELSE Condition with EVAL function in GridView using C# and VB.Net.
VB.Net
<asp:TemplateField HeaderText="Pay">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEditexam" runat="server" Text="Pay Now" Visible='<%# If(getvalu2(Eval("IsPaid")).ToString().ToUpper() = "YES", false, true) %>'
CssClass="btn btn-info"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
C#
<asp:TemplateField HeaderText="Pay">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEditexam" runat="server" Text="Pay Now" Visible='<%# getvalu2(Eval("IsPaid")).ToString().ToUpper() == "YES" ? false:true %>'
CssClass="btn btn-info"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>