Dynamic Template Column Sorting in DataGrid control

Discussion in 'ASP .Net Datagrid Control' started by Vishal, Jun 8, 2004.

  1. Vishal

    Vishal Guest

    Hi,

    am facing a problem while using ASP.NET Datagrid Template Columns
    generated dynamically.

    Scenario:
    -------------

    1) I have a custom datagrid control class (inheriting from
    System.Web.UI.WebControls.DataGrid).
    In the constructor of this class i dynamically register the
    OnSortCommand for the grid.

    2) I have another custom CustomHeaderTemplate class inheriting from
    ITemplate, which we are using to customize the header
    column template for our custom DataGrid control.

    3) In the BindData event of this class, am adding a LinkButton an
    set the properties as follows.

    ---
    DataGridItem container = (DataGridItem) pnl.NamingContainer;
    LinkButton lb = new LinkButton();
    lb.Text = "Employee Name";
    lb.CommandName = "sort";
    lb.CommandArgument = "EmpName"; //Name of the Column in the grid
    DataSource
    container.Controls.Add(tb);
    ---

    4) In the aspx page containing the grid, set the HeaderTemplate of the
    grid to this custom class

    DataGridObject.HeaderTemplate = new CustomHeaderTemplate ();

    5) The Link buttons appear fine in the column header, but when
    clicked,
    the OnSortCommand command of my custom datagrid does not fire.

    Could anyone please let know what else needs to be done in order for
    the Sort Command to fire in the case of dynamic DataGrid Template
    Columns?

    Thanks in advance.

    Cheers,
    Vishal Makhija
     
    Vishal, Jun 8, 2004
    #1
    1. Advertising

  2. "Vishal" <> wrote in message
    news:...
    > Hi,
    >
    > am facing a problem while using ASP.NET Datagrid Template Columns
    > generated dynamically.
    >
    > Scenario:
    > -------------
    >
    > 1) I have a custom datagrid control class (inheriting from
    > System.Web.UI.WebControls.DataGrid).
    > In the constructor of this class i dynamically register the
    > OnSortCommand for the grid.
    >
    > 2) I have another custom CustomHeaderTemplate class inheriting from
    > ITemplate, which we are using to customize the header
    > column template for our custom DataGrid control.
    >
    > 3) In the BindData event of this class, am adding a LinkButton an
    > set the properties as follows.
    >
    > ---
    > DataGridItem container = (DataGridItem) pnl.NamingContainer;
    > LinkButton lb = new LinkButton();
    > lb.Text = "Employee Name";
    > lb.CommandName = "sort";
    > lb.CommandArgument = "EmpName"; //Name of the Column in the grid
    > DataSource
    > container.Controls.Add(tb);
    > ---
    >
    > 4) In the aspx page containing the grid, set the HeaderTemplate of the
    > grid to this custom class
    >
    > DataGridObject.HeaderTemplate = new CustomHeaderTemplate ();
    >
    > 5) The Link buttons appear fine in the column header, but when
    > clicked,
    > the OnSortCommand command of my custom datagrid does not fire.
    >
    > Could anyone please let know what else needs to be done in order for
    > the Sort Command to fire in the case of dynamic DataGrid Template
    > Columns?


    Does the ItemCommand event fire? If so, check in the ItemCommand event for
    CommandName == "sort" and then fire the SortCommand event yourself.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jun 8, 2004
    #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. John E.
    Replies:
    3
    Views:
    4,476
    masoud bayan
    Mar 25, 2005
  2. Vishal

    Dynamic Template Column Sorting in DataGrid control

    Vishal, Jun 8, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    186
    John Saunders
    Jun 8, 2004
  3. John E.

    Move bound column to right of dynamic column in datagrid?

    John E., Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    234
    Elton Wang
    Mar 28, 2005
  4. Dan

    Static DataGrid - Dynamic Column Order - Sorting Issue

    Dan, Jul 26, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    147
    Dip Gada
    Aug 11, 2006
  5. Vishal

    Dynamic Template Column Sorting in DataGrid control

    Vishal, Jun 8, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    137
    John Saunders
    Jun 8, 2004
Loading...

Share This Page