.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
294 Points
679 Posts
Hide Data Dynamic Column in Gridview
Sep 17, 2019 05:59 PM|Gopi.MCA|LINK
Hello
In my gridview its bind data automatically
my gridview look like this
i want to hide 3 column how to do so
Contributor
3370 Points
1409 Posts
Re: Hide Data Dynamic Column in Gridview
Sep 18, 2019 02:08 AM|samwu|LINK
Hi Gopi.MCA,
You can set columns invisible in your GridView's RowDataBound event.
The code:
<asp:GridView ID="GridView1" runat="server" Font-Bold="False" Font-Names="Calibri" Font-Size="12pt" OnRowDataBound="GridView1_RowDataBound"> </asp:GridView> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country"), new DataColumn("Salary") }); dt.Rows.Add(1, "John Hammond", "United States", 70000); dt.Rows.Add(2, "Mudassar Khan", "India", 40000); dt.Rows.Add(3, "Suzanne Mathews", "France", 30000); dt.Rows.Add(4, "Robert Schidner", "Russia", 50000); GridView1.DataSource = dt; GridView1.DataBind(); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[1].Visible = false; e.Row.Cells[2].Visible = false; e.Row.Cells[3].Visible = false; }
The result:
Best regards,
Sam
Member
294 Points
679 Posts
Re: Hide Data Dynamic Column in Gridview
Sep 18, 2019 02:50 AM|Gopi.MCA|LINK
Hi
i used above code im getting one problem
column it hided perfect still it showing header how to solve this?
Thanking You
Contributor
3370 Points
1409 Posts
Re: Hide Data Dynamic Column in Gridview
Sep 18, 2019 03:09 AM|samwu|LINK
Hi Gopi.MCA,
Can you show me your aspx code?
In my side, the header also be hided.
Best regards,
Sam