Hii setwell,
Please refer below sample.
HTML
<asp:GridView ID="gvComputer" runat="server" AutoGenerateColumns="false" RowStyle-HorizontalAlign="Center" RowStyle-VerticalAlign="Middle" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField HeaderText="Approve">
<ItemTemplate>
<asp:LinkButton ID="lnkApp" Text="APP" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reject">
<ItemTemplate>
<asp:LinkButton ID="lnkRej" Text="REJ" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PartId" HeaderText="Part Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Type" HeaderText="Type" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="ApproveDate" HeaderText="Approve Date" DataFormatString="{0:dd/MMM/yyyy}" />
<asp:BoundField DataField="RejectDate" HeaderText="Reject Date" DataFormatString="{0:dd/MMM/yyyy}" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GridView();
}
}
private void GridView()
{
string constring = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 PartId, Name, Type, Status, ApproveDate, RejectDate FROM Computer", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
gvComputer.DataSource = dt;
gvComputer.DataBind();
if (dt.Rows[0]["Status"].ToString().ToLower() == "app")
{
gvComputer.Columns[0].Visible = false;
gvComputer.Columns[6].Visible = false;
}
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.GridView()
End If
End Sub
Private Sub GridView()
Dim constring As String = ConfigurationManager.ConnectionStrings("constring").ConnectionString
Using con As SqlConnection = New SqlConnection(constring)
Using cmd As SqlCommand = New SqlCommand("SELECT TOP 1 PartId, Name, Type, Status, ApproveDate, RejectDate FROM Computer", con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
gvComputer.DataSource = dt
gvComputer.DataBind()
If dt.Rows(0)("Status").ToString().ToLower() = "app" Then
gvComputer.Columns(0).Visible = False
gvComputer.Columns(6).Visible = false
End If
End Using
End Using
End Using
End Using
End Sub
Screenshot