DataGrid dynamic columns / firing events

Discussion in 'ASP .Net Web Controls' started by Abelardo Vacca, Jan 12, 2006.

  1. Hello,

    I have a DataGrid with columns build dynamically, the grid supports sorting.
    I create the columns OnInit so the sort event will fire when the headers are
    clicked.

    All this works fine.

    Now, one requirement is for the user to have the option of selecting
    predefined layouts for the DataGrid (differents columns in difference order)
    .... I added this feature using a dropdown list control with the layouts names
    on top of the page ...

    The problem is, since I am creating the DataGrid columns OnInit, the
    "selected layout" is NOT available yet (since the dropdown list control
    SelectedItemChanged event has not been handled yet ... it can't be handled
    before OnInit)

    The only way to create the correct columns for the DataGrid would be to
    create them after OnInit, but that way I won't have a DataGrid responsive to
    sorting events.

    Enter Catch-22.

    I even tried creating ALL possible columns during OnInit, and later on
    deleting the columns and recreating the correct ones (after learing the
    "selected layout"), but this creates a really weird behavior when sorting the
    columns - clicking one columns could result in sorting another columns -

    Any ideas? Could anyone confirm if I am correct by creating the DataGrid
    Columns OnInit, or is there any other way of creating these columns without
    losing the events?

    Thanks
    --
    Abelardo Vacca
    Abelardo Vacca, Jan 12, 2006
    #1
    1. Advertising

  2. You are correct in creating the datagrid columns OnInit. Separate the
    routine that creates the datagrid in a separate function that is called from
    both OnInit and after you handled SelectedIndexChanged event. Persist an
    indicator of the layout change to redo it upon next postback in the OnInit
    event handling.

    Function DataGridCreate
    - if Session(“LayoutIndicatorsâ€)
    o retrieve those indicators
    - create the datagrid
    OnInit:
    - call the DataGridCreate
    OnSelectedIndexChanged
    - Save Session(“LayoutIndicatorsâ€)
    - Call the DataGridCreate

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Abelardo Vacca" wrote:

    > Hello,
    >
    > I have a DataGrid with columns build dynamically, the grid supports sorting.
    > I create the columns OnInit so the sort event will fire when the headers are
    > clicked.
    >
    > All this works fine.
    >
    > Now, one requirement is for the user to have the option of selecting
    > predefined layouts for the DataGrid (differents columns in difference order)
    > ... I added this feature using a dropdown list control with the layouts names
    > on top of the page ...
    >
    > The problem is, since I am creating the DataGrid columns OnInit, the
    > "selected layout" is NOT available yet (since the dropdown list control
    > SelectedItemChanged event has not been handled yet ... it can't be handled
    > before OnInit)
    >
    > The only way to create the correct columns for the DataGrid would be to
    > create them after OnInit, but that way I won't have a DataGrid responsive to
    > sorting events.
    >
    > Enter Catch-22.
    >
    > I even tried creating ALL possible columns during OnInit, and later on
    > deleting the columns and recreating the correct ones (after learing the
    > "selected layout"), but this creates a really weird behavior when sorting the
    > columns - clicking one columns could result in sorting another columns -
    >
    > Any ideas? Could anyone confirm if I am correct by creating the DataGrid
    > Columns OnInit, or is there any other way of creating these columns without
    > losing the events?
    >
    > Thanks
    > --
    > Abelardo Vacca
    Phillip Williams, Jan 12, 2006
    #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. =?Utf-8?B?U2hvdXJpZQ==?=
    Replies:
    1
    Views:
    7,873
    =?Utf-8?B?U2hvdXJpZQ==?=
    Jan 21, 2004
  2. SevDer
    Replies:
    2
    Views:
    1,285
    Walter Wang [MSFT]
    Nov 13, 2007
  3. Alfred Sehmueller

    Dynamic Columns, UpdateCommand not firing

    Alfred Sehmueller, Feb 23, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    154
    Alfred Sehmueller
    Feb 23, 2004
  4. tsarna

    Sort not firing PostBack event using Dynamic Columns

    tsarna, Jun 23, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    180
    tsarna
    Jun 28, 2004
  5. Replies:
    1
    Views:
    323
    Teemu Keiski
    Apr 17, 2006
Loading...

Share This Page