Data grid columns still showing up

Discussion in 'ASP .Net Datagrid Control' started by Angel Fernendez, Nov 21, 2003.

  1. I am using a run-time connection to populate a datagrid and when I try to
    hide my columns it does not work. If I set the column index higher I get an
    error.

    here is the code

    cn.Open();

    SqlCommand cmd = new SqlCommand(sSQL,cn);

    DataTable dt = new DataTable();

    SqlDataAdapter da = new SqlDataAdapter(cmd);

    da.Fill(dt);

    DataGrid1.DataSource = dt;

    DataGrid1.DataBind();

    this.DataGrid1.Columns[1].Visible = false;

    does anyone have any suggestions?
    Please help!!

    Thanks!!
     
    Angel Fernendez, Nov 21, 2003
    #1
    1. Advertising

  2. Angel Fernendez

    source Guest

    According to MSDN, you can only manipulate (specially using the visible
    property) only the explicitly declared columns. If you have
    'AutoGenerateColumns' = 'True' for your datagrid then you wont be able to
    use the Columns collection for the datagrid.
    Even I am trying to hide a column which is not explicitly declared.

    Anybody who knows how to hide a column which is not explicitly declared let
    me know.

    "Angel Fernendez" <> wrote in message
    news:...
    > I am using a run-time connection to populate a datagrid and when I try to
    > hide my columns it does not work. If I set the column index higher I get

    an
    > error.
    >
    > here is the code
    >
    > cn.Open();
    >
    > SqlCommand cmd = new SqlCommand(sSQL,cn);
    >
    > DataTable dt = new DataTable();
    >
    > SqlDataAdapter da = new SqlDataAdapter(cmd);
    >
    > da.Fill(dt);
    >
    > DataGrid1.DataSource = dt;
    >
    > DataGrid1.DataBind();
    >
    > this.DataGrid1.Columns[1].Visible = false;
    >
    > does anyone have any suggestions?
    > Please help!!
    >
    > Thanks!!
    >
    >
     
    source, Dec 29, 2003
    #2
    1. Advertising

  3. Angel Fernendez

    Greg Baugher Guest

    I have a column in a datagrid that I don't want displayed, but still need
    access to the data. I changed the column width in the DataGridTableStyle.

    "source" <> wrote in message
    news:e$...

    > According to MSDN, you can only manipulate (specially using the visible
    > property) only the explicitly declared columns. If you have
    > 'AutoGenerateColumns' = 'True' for your datagrid then you wont be able to
    > use the Columns collection for the datagrid.
    > Even I am trying to hide a column which is not explicitly declared.
    >
    > Anybody who knows how to hide a column which is not explicitly declared

    let
    > me know.
    >
    > "Angel Fernendez" <> wrote in message
    > news:...
    > > I am using a run-time connection to populate a datagrid and when I try

    to
    > > hide my columns it does not work. If I set the column index higher I get

    > an
    > > error.
    > >
    > > here is the code
    > >
    > > cn.Open();
    > >
    > > SqlCommand cmd = new SqlCommand(sSQL,cn);
    > >
    > > DataTable dt = new DataTable();
    > >
    > > SqlDataAdapter da = new SqlDataAdapter(cmd);
    > >
    > > da.Fill(dt);
    > >
    > > DataGrid1.DataSource = dt;
    > >
    > > DataGrid1.DataBind();
    > >
    > > this.DataGrid1.Columns[1].Visible = false;
    > >
    > > does anyone have any suggestions?
    > > Please help!!
    > >
    > > Thanks!!
    > >
    > >

    >
    >
     
    Greg Baugher, Jan 28, 2004
    #3
    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. =?Utf-8?B?U2ltb24=?=

    Problems with dynamic template columns in a data grid

    =?Utf-8?B?U2ltb24=?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,129
    rizwan328
    Nov 22, 2007
  2. =?Utf-8?B?cG11ZA==?=
    Replies:
    2
    Views:
    1,009
    =?Utf-8?B?cG11ZA==?=
    Jan 10, 2005
  3. Ryan Ternier

    Data Grid - Update Columns

    Ryan Ternier, Feb 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,041
    Ryan Ternier
    Feb 16, 2005
  4. gbattine
    Replies:
    0
    Views:
    899
    gbattine
    Jul 6, 2006
  5. Roger Frei

    Adding columns dynamically to data grid

    Roger Frei, Jun 15, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    2,215
    Roger Frei
    Jun 15, 2007
Loading...

Share This Page