GridView - invisible column and checkbox column

I'm using the GridView.   I want to make a column invisible.  It is bound to a DataTable.  I have encountered a number of issue in trying to accomplish this.  

The ColumnName of the column in the DataTable is used as the column header text.  If I set this  to nothing, I get default text in the Column Header of "Column1".   Because I can't set the ColumnName of the column to nothing, this prevent the column form being invisible even if I set the invisible property to false and width to 0.   Bottom line, I can't get this column to totally disappear.  Is there a trick?  The invisible column is an a key value for the data in the row.  Is there a way to associate a key value with the row, without using a distinct column?  

Also, one of my columns is a check box.  I get the check box in theGridView by using a column in the DataTable with DataType = System.Type.GetType("System.Boolean").  However, the check box column is disabled.  How can I make it enabled?

Thanks
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
drypzCommented:
Hi! You may hide your column during databound event of your row. Something like this
    protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        //assuming you want to hide column 0
        //you can hide to the user but still you can access its value
        e.Row.Cells[0].Attributes.Add("style", "display:none");
    }

Your question regarding disabled checkbox, this is enabled during Edit Mode of your gridview. 

Hope this helps.

Open in new window

0
 
Kumaraswamy RCommented:
Hi

Bellow url give some information

http://www.asp.net/Learn/data-access/tutorial-52-vb.aspx
0
 
samsymonCommented:
on rowdatabount of the grid
just add

e.Row.Cells(<COLUMN YOU WANT TO HIDE>).Style.Add("display", "none");

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
HLRosenbergerAuthor Commented:
That did the trick!  Thanks!
0
 
HLRosenbergerAuthor Commented:
drypz:

On how to enable the check box column, "enabled during Edit Mode of your gridview".  Could you provide code example?  I'm new to .NET...
0
 
HLRosenbergerAuthor Commented:
drypz:

Also, would you have any info on this:  I have the GridView on a panel, so that I can scroll it.  All controls have that little tab at the upper left.  I want to align the tops of the GridView and the panel.  However, I cannot, visually, move the GridView to align with the top of the panel - that  little tab seems to prevent this.  How can I align the top of the  GridView with the top of the panel?   If you know the answer, I'm open another question, because you should get the credit for it.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.