Dynamically Adding Bound Columns Won't Sort

Discussion in 'ASP .Net Datagrid Control' started by Mark, Nov 24, 2003.

  1. Mark

    Mark Guest

    All-

    I'm basically creating a user control which contains a datagrid that will be
    used throughout our application by all pages.
    My user control contains a datagrid control and I expose methods to add a
    bound column to the grid.
    So when they call this function and pass in the field name and title, I
    dynamically add this new bound column to the
    grid. It works when loaded for the first time and the paging works fine
    also.
    The only problem is that the Sort event doesn't fire. The bound columns are
    being recreated when the page reloads,
    so the grid object has them. I don't get it.


    Any help would be great. Thanks
    Mark, Nov 24, 2003
    #1
    1. Advertising

  2. Mark

    Mark Guest

    FYI:

    When I binded the data back to the grid on load, the event fired. Doesn't
    make sense though, because when you add static columns
    to the grid in Html, you don't have to do that. What this means is that if
    you create the columns dynamically in code, you have to rebind the grid in
    order to get the sort event, then figure out how to sort your data, and then
    rebind once again. Two binds in one postback.

    Either I'm missing something, or this is bad design on MS's part.



    "Mark" <> wrote in message
    news:...
    > All-
    >
    > I'm basically creating a user control which contains a datagrid that will

    be
    > used throughout our application by all pages.
    > My user control contains a datagrid control and I expose methods to add a
    > bound column to the grid.
    > So when they call this function and pass in the field name and title, I
    > dynamically add this new bound column to the
    > grid. It works when loaded for the first time and the paging works fine
    > also.
    > The only problem is that the Sort event doesn't fire. The bound columns

    are
    > being recreated when the page reloads,
    > so the grid object has them. I don't get it.
    >
    >
    > Any help would be great. Thanks
    >
    >
    Mark, Nov 24, 2003
    #2
    1. Advertising

  3. Mark

    Jos Guest

    "Mark" <> wrote in message
    news:...
    > FYI:
    >
    > When I binded the data back to the grid on load, the event fired. Doesn't
    > make sense though, because when you add static columns
    > to the grid in Html, you don't have to do that. What this means is that

    if
    > you create the columns dynamically in code, you have to rebind the grid in
    > order to get the sort event, then figure out how to sort your data, and

    then
    > rebind once again. Two binds in one postback.
    >
    > Either I'm missing something, or this is bad design on MS's part.


    This is correct. In order to get postback from controls that are created
    dynamically, you need to recreate them at postback.
    Then you can handle the postback event and rebuild your page once again.

    I wouldn't say it's bad design, because it's not easy to handle events from
    controls that don't exist anymore.

    --

    Jos
    Jos, Nov 26, 2003
    #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?Sm9u?=

    Datagrid, adding bound columns.

    =?Utf-8?B?Sm9u?=, Feb 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    425
    =?Utf-8?B?Sm9u?=
    Feb 15, 2006
  2. slapdash

    Dynamically data-bound columns versus asp:ButtonColumn

    slapdash, Nov 2, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    140
    slapdash
    Nov 2, 2005
  3. et

    Getting data out of dynamically bound columns

    et, May 14, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    119
  4. Bman

    Access to dynamically bound columns

    Bman, Oct 7, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    129
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    855
    Vinki
    Apr 25, 2007
Loading...

Share This Page