Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've to hide two columns in a gridview
Posted

Hi ,
Check this
C#
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
 {
     e.Row.Cells[1].Visible = false;
 }


Best Regards
M.Mitwalli
 
Share this answer
 
The all the columns of datagrid is autoupdated from the database table.
To disable the auto generation of columns, simply change the AutoGenerateColumns property to false of your datagrid.

Now your datagrid has no columns, and you can put any no. of columns from database with datatable.

I hope you know how to add columns in datatable.

The another solution is that try this:
C#
OledbDataAdapter da = new OledbDataAdapter("select [column],[column] from [tablename]",[connection object]);
DataSet ds = new DataSet();

da.Fill(ds,"[tablename]");

GridView1.DataSource=ds.Tables("[tablename]");
GridView1.DataBind();

This code will work with msaccess database.

Thank you.
 
Share this answer
 
v4
after assigning the datasource to the grid view

check if the column exists
like

C#
id(dg.Columns.Contains("ColumnName"))
 dg.Column["ColumnName"].visible = false;
 
Share this answer
 
v2
Comments
DhivyaThangavel 23-May-12 8:39am    
grdview.column is not available

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