How to hide columns in Datagrid

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default How to hide columns in Datagrid

    Hi All,
    I am using Data binding with DataGrid. I need to hide column in the grid
    using
    DataGrid1.Columns(1).Visible = False

    But I get the following error message

    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: Index was out of
    range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    Source Error:

    Line 119:
    Line 120: Private Sub Button1_Click(ByVal sender As System.Object, ByVal
    e As System.EventArgs) Handles Button1.Click
    Line 121: DataGrid1.Columns(1).Visible = False
    Line 122: End Sub
    Line 123:


    It seems that Datagrid does not recognize the columns created at runtime.

    Any idea how to do this?

    Thanks in advance.



    Jie


    J Gao Guest

  2. Similar Questions and Discussions

    1. How to Hide & show the columns in ADVANCED DATAGRID.?
      HI, Am working with Advanced Datagrid. Problem am facing is.. i want to hide & show the columns in AdvancedDataGridColumnGroup. By default am...
    2. CFGRID, Using Query - How do I hide columns?
      This might make no sense or I might know the answer, but not know I know it ... How can I hide columns in a query generated cfgrid? You say,...
    3. Hide Columns
      Dar all, Could any one tell me how to hide columns in datagrid in the run time?
    4. Columns and Inherited Datagrid...Active Schema does not support columns
      I have a class which has inherited from datagrid, to provide some custom functionality, row select, mouse overs etc All is working fine apart from...
    5. Can you hide columns generated with AutoGenerateColumns?
      I noticed that columns generated with AutoGenerateColumns are not part of the columns collection. So how can they be hidden at run time? Thanks...
  3. #2

    Default Re: How to hide columns in Datagrid

    I got it. Use
    Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DataGrid1.ItemCreated

    Select Case e.Item.ItemType

    Case ListItemType.Header

    e.Item.Cells(1).Visible = False

    e.Item.Cells(2).Visible = False




    End Sub

    "J Gao" <jie.gao@tequilasoftware.com> wrote in message
    news:uJa7CwFUDHA.2180@TK2MSFTNGP12.phx.gbl...
    > Hi All,
    > I am using Data binding with DataGrid. I need to hide column in the grid
    > using
    > DataGrid1.Columns(1).Visible = False
    >
    > But I get the following error message
    >
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    >
    > Exception Details: System.ArgumentOutOfRangeException: Index was out of
    > range. Must be non-negative and less than the size of the collection.
    > Parameter name: index
    >
    > Source Error:
    >
    > Line 119:
    > Line 120: Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal
    > e As System.EventArgs) Handles Button1.Click
    > Line 121: DataGrid1.Columns(1).Visible = False
    > Line 122: End Sub
    > Line 123:
    >
    >
    > It seems that Datagrid does not recognize the columns created at runtime.
    >
    > Any idea how to do this?
    >
    > Thanks in advance.
    >
    >
    >
    > Jie
    >
    >

    J Gao Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139