Click here to Skip to main content
15,299,443 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am binding a DataSet objetc as a datasource to my GridView. However i want to omit first column from being displayed.
If i write
GridView1.Columns(0).Visible = False

then i get error saying there was some indexing error.
How can this be acheived ???
Also a weird thing is that when I try to count columns it displays me count as 0 !! :O

Updated 8-Nov-17 19:53pm
hitech_s 25-May-12 2:39am
how many columns are there for gridview
Kanaparthi Sureshma Reddy 27-May-15 23:58pm
I have 8 columns and I want to hide all columns except specific column which is I chose from Dropdown list.
Upniwesh 25-May-12 2:44am
total 3 column in table
at 0 index id
at 1 index name
at 2 age
and i want to hide id.........

Please refer: Show / Hide GridView Columns in ASP.NET[^]
Similar discussion:
How to hide ASP.Net Gridview column[^]

Try this: On GridView1.RowDataBound event
GridView1.Columns(0).Visible = False
dgItems.Columns[0].Visible = false;

or try this

protected void bla_RowCreated(object sender, GridViewRowEventArgs e)
    e.Row.Cells[0].Visible = false; // hides the first column

i think it work well
try this:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        e.Row.Cells[0].Visible = false;
Upniwesh 25-May-12 3:15am
Its is correct solution.......
Now working
Narendra Singh Chauhan 1-Jul-15 3:24am
Thanks....Its working.
in gridview OnRowCreate event you can hide the column you want to hide

protected void GridviewRowCreated(object sender,GridViewRowEventArgs e)
            e.Row.Cells[indexofcolumn].Visible = false;
Inside the Gridview RowDataBound event place the given code below it will works.
e.Row.Cells[0].Visible = false;
Tom Marvolo Riddle 25-Oct-13 9:05am
@zohairll:Your answer is copied from solution3.Don't do this you may get downvoted.
I didn't downvote you for this.
You can try this

DataGridView1.Columns("id").Visible = False

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900