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
C#
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

Thanks
Upniwesh
Posted
Updated 8-Nov-17 19:53pm
v2
Comments
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
XML
GridView1.Columns(0).Visible = False
   
v2
dgItems.Columns[0].Visible = false;


or try this


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



http://stackoverflow.com/questions/2091457/how-to-hide-columns-in-an-asp-net-gridview-with-auto-generated-columns[^]


i think it work well
   
try this:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false;
    }
   
v2
Comments
Upniwesh 25-May-12 3:15am
   
Thanks
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

C#
protected void GridviewRowCreated(object sender,GridViewRowEventArgs e)
        {
            e.Row.Cells[indexofcolumn].Visible = false;
        }
   
v3
Inside the Gridview RowDataBound event place the given code below it will works.
e.Row.Cells[0].Visible = false;
   
Comments
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