Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
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 !! Blush | :O
 
Thanks
Upniwesh
Posted 24-May-12 21:36pm
Edited 24-May-12 21:40pm
v2
Comments
hitech_s at 25-May-12 2:39am
   
how many columns are there for gridview
Upniwesh at 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.........
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
}
 

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

i think it work well
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false;
    }
  Permalink  
v2
Comments
Upniwesh at 25-May-12 3:15am
   
Thanks
Its is correct solution.......
Now working
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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;
        }
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Inside the Gridview RowDataBound event place the given code below it will works.
e.Row.Cells[0].Visible = false;
  Permalink  
Comments
Jas24 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

You can try this
 
DataGridView1.Columns("id").Visible = False
  Permalink  

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

  Print Answers RSS
0 DamithSL 270
1 OriginalGriff 184
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Sergey Alexandrovich Kryukov 125
0 OriginalGriff 7,760
1 DamithSL 5,874
2 Sergey Alexandrovich Kryukov 5,444
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 28 Oct 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100