hidden column in gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vignahari
    New Member
    • Dec 2009
    • 1

    hidden column in gridview

    Hai Friends
    I n my case i am reterieving some datas from the backend
    in that one patricular column in the gridview should be hidden.it should not shown in the screen.in case if is use visible="false" the datas not showing in when clicking the event the text box how to do this pls help me.
    source code:
    ---------------------------------------------
    Code:
    <asp:BoundField DataField="GLAC_NAME" HeaderText="A/cNo">
    <ItemStyle Width="200px" />
    </asp:BoundField>
    this particular column i have to hidden should not shown to the user
    code begin:
    ----------------------------------------------------------
    Code:
    protected void GridLedger_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      try
      {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          e.Row.Attributes.Add("onMouseDown", "var str = document.getElementById('" + e.Row.ClientID + "').cells[1].innerText; document.getElementById('"+TextBox1.ClientID+"').value = str;"); 
    
        }
      }
      catch (System.Exception ex)
      {  
        throw ex;
      }
    }
    here is the code begin in this what cell value i should mention pls help me
    Last edited by Frinavale; Dec 8 '09, 09:12 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Use CSS to hide the column.

    When you use .NET code and you set something to Visible=False that control is not rendered. This means that no HTML code is generated for this control.

    If you need this to exist client side (so that you can do calculations client side) then you need to hide the element using CSS.

    To hide an element you can do one of 2 things with CSS.
    You can use "visible:hidden " or "display:no ne".

    If you use visible:hidden then the element is hidden but the space that it takes up will still show up.

    If you use display:none then the element is not displayed...the refore there is no gap where the element should be like when you use visible:hidden.

    Check out w3c for more information on the visible style and the display style.

    I prefer to use display:none because then there is no invisible object taking up room for no reason....but there are some circumstances where this could be useful.

    So try:
    Code:
    <asp:BoundField DataField="GLAC_NAME" HeaderText="A/cNo">
      <ItemStyle CssClass="hideElement"  />
      <HeaderStyle  CssClass="hideElement"  />
    </asp:BoundField>
    Where you have a CSS class defined as:
    Code:
    .hideElement{
      display:none;
    }
    This will hide the header for the column and the column data itself.

    -Frinny

    Comment

    Working...