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. Advertisements

  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. Advertisements

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,815
    Simon
    Jul 9, 2003
  2. Conawapa11
    Replies:
    1
    Views:
    788
    Michael Tkachev
    Nov 14, 2003
  3. David Laub
    Replies:
    0
    Views:
    600
    David Laub
    Aug 3, 2004
  4. Weston Weems
    Replies:
    2
    Views:
    1,792
    Greg Burns
    Sep 29, 2004
  5. xzzy
    Replies:
    3
    Views:
    604
    Teemu Keiski
    Jun 18, 2006
  6. Øyvind Isaksen
    Replies:
    1
    Views:
    1,275
    Øyvind Isaksen
    May 18, 2007
  7. JcFx
    Replies:
    0
    Views:
    541
  8. David A. Coursey

    Refrence image in datagrid with OnItemDataBound

    David A. Coursey, Oct 5, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    196
    Eric Cherng
    Oct 6, 2004
Loading...