GridView Column Hide Or Remove in Asp.Net C#

GridView Column Hide Or Remove

Gridview Display Particular Columns Hide Or Remove Run Time Using Gridview_RowCreated Event in Asp.Net C#.



<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" OnRowCreated="GridView1_RowCreated">
        <asp:BoundField DataField="country" HeaderText="COUNTRY" />
        <asp:BoundField DataField="amount" HeaderText="AMOUNT" />
        <asp:BoundField DataField="name" HeaderText="NAME" />
     <HeaderStyle BackColor="#FF3300" />
            <RowStyle BackColor="Silver" />
            <AlternatingRowStyle BackColor="#9999FF" />

                          C# CODING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.OleDb;
using System.Data;
using System.Data.SqlClient;

public partial class Default4 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        SqlCommand cmd = new SqlCommand("select country,amount,name from country", con);

        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();

        GridView1.DataSource = ds;

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        e.Row.Cells[1].Visible = false;

        //Amount Column Not Show

First - Add New Web Form  - Select GridView From  ToolBox 

Next - Go -To - Edit Column - Add BoundField - Change Header & DataField

Next - Go -To - Edit Column - Add BoundField - Change Header & DataField

Next - Bind Values To GridView  On Page_Load

Next - Select GridView - Go-To - Property - RowCreated 

Next - Visible = False  The Column Cell Values

Next - Run[F5] - WithOut  Column  Hide Show All Column Otherwise Hide The Columns



Post a Comment