I wanted to Hide GridView Header and footer cell or else 1st column if Value Status = "APP" Or If Status = "REJ" Than 2nd Column should hide.
But Problem is that if i am hiding cell value the automatically next column's Cell value setting to current cell.
My output is
Approve | Rejecte | Part Id | Name | Type | Status | Approve Date | Reject Date |
REJ |
1 |
RAM |
DDR4 |
APP |
25-Dec-2022 |
|
Database.
PartId Name Type STATUS ApproveDate RejectDate
1 RAM DDR4 APP 2 022-12-25 NULL
<asp:GridView ID="gvComputer" runat="server" AutoGenerateColumns="false" RowStyle-HorizontalAlign="Center"
RowStyle-VerticalAlign="Middle" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField HeaderText="Approve">
<ItemTemplate>
<asp:LinkButton Text="APP" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rejecte">
<ItemTemplate>
<asp:LinkButton 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>
private void GridView()
{
string conString = ConfigurationManager.ConnectionStrings["Web_Con"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand com = new SqlCommand("SELECT PartId, Name, Type, Status, ApproveDate, RejectDate FROM ComputerParts", con))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(com))
{
using (DataTable dt = new DataTable())
{
adapter.Fill(dt);
gvComputer.DataSource = dt;
gvComputer.DataBind();
}
}
}
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
if( e.Row.Cells[5].Text == "APP")
{
e.Row.Cells[0].Visible = false;
}
}
}