Sorting dynamically created columns in the datagird

Discussion in 'ASP .Net' started by Gaurav Gargate, Oct 5, 2004.

  1. To Group,

    I am creating a datagrid in an ASP.NET project (C#) at the design time.
    I will be adding the columns to the datagird at run time.
    The number of columns, name of the columns, data in the rows etc. will all
    be decided on the run time.
    I am using the simple grid.Columns.Add(BoundColumn).... method.

    BUT I am not able to sort these columns even if the AllowSorting property
    has been set to true.
    I cannot capture any event when I click the header of the data grid.
    The page is posted back on clicking the header but no event is fired.

    How can I sort the columns created on the run time.

    Thanks in Advance,
    Gaurav
     
    Gaurav Gargate, Oct 5, 2004
    #1
    1. Advertising

  2. hi Gaurav,
    You need to give the sort expression for each column that you are adding.
    In the datagrid_sortcommand event you have to get the sortexpression of the
    datagrid and sort the datasource on that column and rebind the datasource to
    the datagrid.
    Check out this link for an exampl
    http://samples.gotdotnet.com/quicks...ef/webctrl/datagrid/doc_datagrid.aspx#sorting
    HTH
    srini

    "Gaurav Gargate" wrote:

    > To Group,
    >
    > I am creating a datagrid in an ASP.NET project (C#) at the design time.
     
    =?Utf-8?B?c3Jpbmk=?=, Oct 5, 2004
    #2
    1. Advertising

  3. Hi Srini...

    Thanks for the urgent reply.
    Infact I had tried out everything that is displayed on the link you
    sent. Just forgot to mention that in my post.. :-(

    The problem was that the dynamically generated columns on the datagrid
    did not generate/evoke any event. So was not able to catch any of them.

    I have however found a way round. I have allowed the auto creation of
    columns on the datagrid and bound the data grid to the dataset I get.
    This has resulted in dynamic columns, as well as all the events are been
    captured.

    Regards,
    Gaurav





    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Gaurav Gargate, Oct 6, 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. Ola Myrgart

    How to insert URL:s into datagird

    Ola Myrgart, Oct 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    364
    Ola Myrgart
    Oct 21, 2003
  2. Replies:
    5
    Views:
    630
  3. msimmons
    Replies:
    0
    Views:
    544
    msimmons
    Jul 16, 2009
  4. Anna Schmidt

    eventhandler of a programmatically created datagird

    Anna Schmidt, Mar 2, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    125
  5. Korneel Vandamme

    sorting dynamically created columns in a datagrid

    Korneel Vandamme, Sep 30, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    148
    Korneel Vandamme
    Sep 30, 2004
Loading...

Share This Page