eventhandler of a programmatically created datagird

Discussion in 'ASP .Net Datagrid Control' started by Anna Schmidt, Mar 2, 2004.

  1. Anna Schmidt

    Anna Schmidt Guest

    Hello,

    I have a programmatically created datagrid (no def in the aspx-file)


    dg2.DataBind();
    holder.Controls.Add(dg2); // placeholder


    in the method InitializeComponent i want to add events (sorting paging) etc.
    to this Datagrid dg2:

    private void InitializeComponent()
    {
    this.dg2.SortCommand += new
    System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dg_Sort);
    ....}

    but unfortunately it doesn't work..nothings happens? or sometimes VS deletes
    this line

    Any idea?

    thank you

    as
     
    Anna Schmidt, Mar 2, 2004
    #1
    1. Advertising

  2. Anna Schmidt

    SB Guest

    Anna,

    I already had that problem in the past, where indeed, VS removes the line
    from the initializecomponent method.
    An easy workaround is to call a method that initialize the events from
    within the page_load method, and in that case, it is no longer removed by
    VS.
    EX:
    void Page_Load(){
    HookEventsOnControls();
    }
    private void HookEventsOnControls(){
    this.dg2.SortCommand += new
    System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dg_Sort);
    }
    "Anna Schmidt" <> wrote in message
    news:c21p1a$1naeu2$-berlin.de...
    > Hello,
    >
    > I have a programmatically created datagrid (no def in the aspx-file)
    >
    >
    > dg2.DataBind();
    > holder.Controls.Add(dg2); // placeholder
    >
    >
    > in the method InitializeComponent i want to add events (sorting paging)

    etc.
    > to this Datagrid dg2:
    >
    > private void InitializeComponent()
    > {
    > this.dg2.SortCommand += new
    > System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dg_Sort);
    > ...}
    >
    > but unfortunately it doesn't work..nothings happens? or sometimes VS

    deletes
    > this line
    >
    > Any idea?
    >
    > thank you
    >
    > as
    >
    >
    >
    >
    >
     
    SB, Mar 2, 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. Ola Myrgart

    How to insert URL:s into datagird

    Ola Myrgart, Oct 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    360
    Ola Myrgart
    Oct 21, 2003
  2. Douglas Gage
    Replies:
    0
    Views:
    414
    Douglas Gage
    Jan 14, 2004
  3. Karl
    Replies:
    0
    Views:
    541
  4. Gaurav Gargate
    Replies:
    2
    Views:
    584
    Gaurav Gargate
    Oct 6, 2004
  5. Replies:
    3
    Views:
    2,161
    sloan
    Aug 1, 2006
Loading...

Share This Page