hiding a Datagrid column

Discussion in 'ASP .Net Datagrid Control' started by samuel Mesel, May 21, 2004.

  1. samuel Mesel

    samuel Mesel Guest

    I'm developing an ASP.NET application. I have a datagrid that has
    7 columns. The first 3 columns contain buttons (Select, Edit, and Delete)
    The next 4 contain data (Table name, Change Description, Change Date,
    and Table ID). I need to have the Table ID of the user's selected
    table - I use it later when I go to edit or delete the table. (The
    editing is done on a seperate screen because the description field i
    larger than I want to fit into a datagrid). But, I would like to hide
    the Table ID column - the user does not need to see it.

    I have a problem trying to set the column's visible property to false
    When I run the page with the code:
    Datagrid.Columns(6).visible = Fals
    I receive an error that the index is out of range. I receive the sam
    error if I try to blank out columns 3,4, or 5. The only time it work
    correctly is when I blank out columns 0, 1, or 2 (the button columns)
    I created the button columns using the Datagrid Property Builder in th
    Visual Studio.NET IDE.

    Any idea how I can get the visible property to work on the non-butto
    columns
     
    samuel Mesel, May 21, 2004
    #1
    1. Advertising

  2. ' Visual Basic
    DataGrid1.Columns(1).Visible = Not (DataGrid1.Columns(1).Visible)

    // C#
    DataGrid1.Columns[1].Visible = !(DataGrid1.Columns[1].Visible);

    --
    Omar Squiabro
    Enterprise Technologies & Software Design
    Project Manager
    www.etsdpr.com
    Tel. 1-787-644-5981
    "samuel Mesel" <> wrote in message
    news:...
    > I'm developing an ASP.NET application. I have a datagrid that has
    > 7 columns. The first 3 columns contain buttons (Select, Edit, and

    Delete).
    > The next 4 contain data (Table name, Change Description, Change Date,
    > and Table ID). I need to have the Table ID of the user's selected
    > table - I use it later when I go to edit or delete the table. (The
    > editing is done on a seperate screen because the description field is
    > larger than I want to fit into a datagrid). But, I would like to hide
    > the Table ID column - the user does not need to see it.
    >
    > I have a problem trying to set the column's visible property to false.
    > When I run the page with the code:
    > Datagrid.Columns(6).visible = False
    > I receive an error that the index is out of range. I receive the same
    > error if I try to blank out columns 3,4, or 5. The only time it works
    > correctly is when I blank out columns 0, 1, or 2 (the button columns).
    > I created the button columns using the Datagrid Property Builder in the
    > Visual Studio.NET IDE.
    >
    > Any idea how I can get the visible property to work on the non-button
    > columns?
    >
     
    Omar Squiabro\(ETSD Corp.\), May 21, 2004
    #2
    1. Advertising

  3. How do you create the last 4 columns?

    Eliyahu

    "samuel Mesel" <> wrote in message
    news:...
    > I'm developing an ASP.NET application. I have a datagrid that has
    > 7 columns. The first 3 columns contain buttons (Select, Edit, and

    Delete).
    > The next 4 contain data (Table name, Change Description, Change Date,
    > and Table ID). I need to have the Table ID of the user's selected
    > table - I use it later when I go to edit or delete the table. (The
    > editing is done on a seperate screen because the description field is
    > larger than I want to fit into a datagrid). But, I would like to hide
    > the Table ID column - the user does not need to see it.
    >
    > I have a problem trying to set the column's visible property to false.
    > When I run the page with the code:
    > Datagrid.Columns(6).visible = False
    > I receive an error that the index is out of range. I receive the same
    > error if I try to blank out columns 3,4, or 5. The only time it works
    > correctly is when I blank out columns 0, 1, or 2 (the button columns).
    > I created the button columns using the Datagrid Property Builder in the
    > Visual Studio.NET IDE.
    >
    > Any idea how I can get the visible property to work on the non-button
    > columns?
    >
     
    Eliyahu Goldin, May 23, 2004
    #3
  4. samuel Mesel

    samuel Mesel Guest

    Omar
    Thanks for your reply, but you didn't see my whole descriptio. If you read it through, you'll notice that I mention I tried to do what you suggested and it didn't work...
    I'm trying to hide one of the data columns, if I do it it will be able to hide one of the command-buttons, or it gives me an error

    Sa
     
    samuel Mesel, May 25, 2004
    #4
  5. samuel Mesel

    samuel Mesel Guest

    Hi Eliyahu

    Please see the following code

    I create a data table (odt) and a data row (odr). I use a data reader t
    retrieve records from the database. I then add column headers to the
    data table through statements such as

    odt.Columns.Add(New DataColumn("Table Name", GetType(String))

    I loop through the retrieved records, and for each one, I
    create a new data row:
    odr = odt.NewRow(
    put each of the 4 data fields into the data row
    odr(0) = datareader(0
    odr(1) = datareader(1)
    etc
    add the data row to the data table
    odt.Rows.Add(odr

    Finally, I put the data from the DataTable into the DataGrid as follows
    Dim odv As New DataView(odt
    datagrid.DataSource = od
    datagrid.DataBind(
     
    samuel Mesel, May 25, 2004
    #5
  6. Samuel,

    Make sure that datagrid.AutoGenerateColumns is set to true. If it is not,
    you have to create the columns of the datagrid yourself, either in design or
    run time, with specifying DataField property for each column.

    Eliyahu

    "samuel Mesel" <> wrote in message
    news:...
    > Hi Eliyahu,
    >
    > Please see the following code:
    >
    > I create a data table (odt) and a data row (odr). I use a data reader to
    > retrieve records from the database. I then add column headers to the
    > data table through statements such as:
    >
    > odt.Columns.Add(New DataColumn("Table Name", GetType(String)))
    >
    > I loop through the retrieved records, and for each one, I:
    > create a new data row:
    > odr = odt.NewRow()
    > put each of the 4 data fields into the data row:
    > odr(0) = datareader(0)
    > odr(1) = datareader(1)
    > etc.
    > add the data row to the data table:
    > odt.Rows.Add(odr)
    >
    > Finally, I put the data from the DataTable into the DataGrid as follows:
    > Dim odv As New DataView(odt)
    > datagrid.DataSource = odv
    > datagrid.DataBind()
    >
     
    Eliyahu Goldin, May 27, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michelle Stone
    Replies:
    0
    Views:
    419
    Michelle Stone
    Oct 15, 2003
  2. David Freeman

    DataGrid - Hiding a Column - Not Working

    David Freeman, Oct 22, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    509
  3. BobRoyAce
    Replies:
    2
    Views:
    4,529
    BobRoyAce
    Jan 20, 2005
  4. jack

    Hiding DataGrid column

    jack, May 11, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    369
    Mark Rae
    May 11, 2007
  5. Ste
    Replies:
    41
    Views:
    814
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page