URGENT question about binding collection to a datagrid onitemdatabound

Discussion in 'ASP .Net Datagrid Control' started by ITnerd, Oct 31, 2003.

  1. ITnerd

    ITnerd Guest

    The following code works to hide specific columns before they are bound to a
    datagrid that has "autogeneratecolumns=true"
    enabled. My question is: is there any way to do the same from a bindable
    user defined collection? I have a "message" class that I don't want to have
    to
    munge into a DataTable to get the desired effect.

    public void Item_Bound(Object sender, DataGridItemEventArgs e)
    {

    DataTable dt = MyDataGrid.DataSource as DataTable;
    DataColumnCollection dc = dt.Columns;
    e.Item.Cells[dc.IndexOf(dc["MessageText"])].Visible = false;

    }

    Thanks in advance.
     
    ITnerd, Oct 31, 2003
    #1
    1. Advertising

  2. Hi

    I think that you can use this code, for any datasource, to hide your column:

    public void Item_Bound(Object sender, DataGridItemEventArgs e)
    {
    foreach(TableCell cell in e.Item.Cells)
    {
    if(cell.Text == "MessageText") cell.Visible = false;
    }
    }

    Giorgio

    "ITnerd" <> ha scritto nel messaggio
    news:...
    > The following code works to hide specific columns before they are bound to

    a
    > datagrid that has "autogeneratecolumns=true"
    > enabled. My question is: is there any way to do the same from a bindable
    > user defined collection? I have a "message" class that I don't want to

    have
    > to
    > munge into a DataTable to get the desired effect.
    >
    > public void Item_Bound(Object sender, DataGridItemEventArgs e)
    > {
    >
    > DataTable dt = MyDataGrid.DataSource as DataTable;
    > DataColumnCollection dc = dt.Columns;
    > e.Item.Cells[dc.IndexOf(dc["MessageText"])].Visible = false;
    >
    > }
    >
    > Thanks in advance.
    >
    >
    >
     
    Giorgio Parmeggiani, Nov 2, 2003
    #2
    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. Steven
    Replies:
    1
    Views:
    1,651
    Simon
    Jul 9, 2003
  2. Weston Weems
    Replies:
    2
    Views:
    1,681
    Greg Burns
    Sep 29, 2004
  3. xzzy
    Replies:
    3
    Views:
    499
    Teemu Keiski
    Jun 18, 2006
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    1,001
    Øyvind Isaksen
    May 18, 2007
  5. JcFx
    Replies:
    0
    Views:
    291
Loading...

Share This Page