csharp syntax help

Discussion in 'ASP .Net' started by =?Utf-8?B?cm9kY2hhcg==?=, Feb 8, 2007.

  1. hey all,
    i'm inside a RowDataBound event and i'd like to dynamically add a button to
    an empty gridView column with a click event handler. i'm having trouble with
    wiring my procedure to the btn click event.

    protected void GridView1_RowDataBound(object sender,
    GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    Button btn = new Button();
    btn.Click += ??? (trying to get the method below to run)

    e.Row.Cells[2].Controls.Add(btn);
    }
    }
    protected void BtnClickEventHandler(object sender, EventArgs e)
    {
    Response.Write("It Worked.");
    }

    any ideas?
    thanks,
    rodchar
    =?Utf-8?B?cm9kY2hhcg==?=, Feb 8, 2007
    #1
    1. Advertising

  2. Hi,

    btn.Click += new EventHandler(this.BtnClickEventHandler);

    BTW, VS 2005 should help you when you write += then press tab.
    --
    Milosz


    "rodchar" wrote:

    > hey all,
    > i'm inside a RowDataBound event and i'd like to dynamically add a button to
    > an empty gridView column with a click event handler. i'm having trouble with
    > wiring my procedure to the btn click event.
    >
    > protected void GridView1_RowDataBound(object sender,
    > GridViewRowEventArgs e)
    > {
    > if (e.Row.RowType == DataControlRowType.DataRow)
    > {
    > Button btn = new Button();
    > btn.Click += ??? (trying to get the method below to run)
    >
    > e.Row.Cells[2].Controls.Add(btn);
    > }
    > }
    > protected void BtnClickEventHandler(object sender, EventArgs e)
    > {
    > Response.Write("It Worked.");
    > }
    >
    > any ideas?
    > thanks,
    > rodchar
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Feb 8, 2007
    #2
    1. Advertising

  3. For some reason the event is not firing when i click the button in the
    gridview, what i am i missing?

    thanks,
    rodchar

    "Milosz Skalecki [MCAD]" wrote:

    > Hi,
    >
    > btn.Click += new EventHandler(this.BtnClickEventHandler);
    >
    > BTW, VS 2005 should help you when you write += then press tab.
    > --
    > Milosz
    >
    >
    > "rodchar" wrote:
    >
    > > hey all,
    > > i'm inside a RowDataBound event and i'd like to dynamically add a button to
    > > an empty gridView column with a click event handler. i'm having trouble with
    > > wiring my procedure to the btn click event.
    > >
    > > protected void GridView1_RowDataBound(object sender,
    > > GridViewRowEventArgs e)
    > > {
    > > if (e.Row.RowType == DataControlRowType.DataRow)
    > > {
    > > Button btn = new Button();
    > > btn.Click += ??? (trying to get the method below to run)
    > >
    > > e.Row.Cells[2].Controls.Add(btn);
    > > }
    > > }
    > > protected void BtnClickEventHandler(object sender, EventArgs e)
    > > {
    > > Response.Write("It Worked.");
    > > }
    > >
    > > any ideas?
    > > thanks,
    > > rodchar
    =?Utf-8?B?cm9kY2hhcg==?=, Feb 8, 2007
    #3
  4. =?Utf-8?B?cm9kY2hhcg==?=

    bruce barker Guest

    you need re-add the handler on postback.

    -- bruce (sqlwork.com)

    rodchar wrote:
    > For some reason the event is not firing when i click the button in the
    > gridview, what i am i missing?
    >
    > thanks,
    > rodchar
    >
    > "Milosz Skalecki [MCAD]" wrote:
    >
    >> Hi,
    >>
    >> btn.Click += new EventHandler(this.BtnClickEventHandler);
    >>
    >> BTW, VS 2005 should help you when you write += then press tab.
    >> --
    >> Milosz
    >>
    >>
    >> "rodchar" wrote:
    >>
    >>> hey all,
    >>> i'm inside a RowDataBound event and i'd like to dynamically add a button to
    >>> an empty gridView column with a click event handler. i'm having trouble with
    >>> wiring my procedure to the btn click event.
    >>>
    >>> protected void GridView1_RowDataBound(object sender,
    >>> GridViewRowEventArgs e)
    >>> {
    >>> if (e.Row.RowType == DataControlRowType.DataRow)
    >>> {
    >>> Button btn = new Button();
    >>> btn.Click += ??? (trying to get the method below to run)
    >>>
    >>> e.Row.Cells[2].Controls.Add(btn);
    >>> }
    >>> }
    >>> protected void BtnClickEventHandler(object sender, EventArgs e)
    >>> {
    >>> Response.Write("It Worked.");
    >>> }
    >>>
    >>> any ideas?
    >>> thanks,
    >>> rodchar
    bruce barker, Feb 8, 2007
    #4
  5. where would i do that at?

    "bruce barker" wrote:

    > you need re-add the handler on postback.
    >
    > -- bruce (sqlwork.com)
    >
    > rodchar wrote:
    > > For some reason the event is not firing when i click the button in the
    > > gridview, what i am i missing?
    > >
    > > thanks,
    > > rodchar
    > >
    > > "Milosz Skalecki [MCAD]" wrote:
    > >
    > >> Hi,
    > >>
    > >> btn.Click += new EventHandler(this.BtnClickEventHandler);
    > >>
    > >> BTW, VS 2005 should help you when you write += then press tab.
    > >> --
    > >> Milosz
    > >>
    > >>
    > >> "rodchar" wrote:
    > >>
    > >>> hey all,
    > >>> i'm inside a RowDataBound event and i'd like to dynamically add a button to
    > >>> an empty gridView column with a click event handler. i'm having trouble with
    > >>> wiring my procedure to the btn click event.
    > >>>
    > >>> protected void GridView1_RowDataBound(object sender,
    > >>> GridViewRowEventArgs e)
    > >>> {
    > >>> if (e.Row.RowType == DataControlRowType.DataRow)
    > >>> {
    > >>> Button btn = new Button();
    > >>> btn.Click += ??? (trying to get the method below to run)
    > >>>
    > >>> e.Row.Cells[2].Controls.Add(btn);
    > >>> }
    > >>> }
    > >>> protected void BtnClickEventHandler(object sender, EventArgs e)
    > >>> {
    > >>> Response.Write("It Worked.");
    > >>> }
    > >>>
    > >>> any ideas?
    > >>> thanks,
    > >>> rodchar

    >
    =?Utf-8?B?cm9kY2hhcg==?=, Feb 8, 2007
    #5
  6. Hi there,

    Handle GridView.RowCreated event and recreate buttons (only if you not
    binding the data)


    protected void GridView1_RowDataBound(object sender,
    GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    Button btn = new Button();
    btn.Click += new EventHandler(this.BtnClickEventHandler);

    e.Row.Cells[2].Controls.Add(btn);
    }
    }

    protected void GridView1_RowCreated(object sender,
    GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow && !IsPostBack)
    {
    Button btn = new Button();
    btn.Click += new EventHandler(this.BtnClickEventHandler);

    e.Row.Cells[2].Controls.Add(btn);
    }
    }

    --
    Milosz


    "rodchar" wrote:

    > where would i do that at?
    >
    > "bruce barker" wrote:
    >
    > > you need re-add the handler on postback.
    > >
    > > -- bruce (sqlwork.com)
    > >
    > > rodchar wrote:
    > > > For some reason the event is not firing when i click the button in the
    > > > gridview, what i am i missing?
    > > >
    > > > thanks,
    > > > rodchar
    > > >
    > > > "Milosz Skalecki [MCAD]" wrote:
    > > >
    > > >> Hi,
    > > >>
    > > >> btn.Click += new EventHandler(this.BtnClickEventHandler);
    > > >>
    > > >> BTW, VS 2005 should help you when you write += then press tab.
    > > >> --
    > > >> Milosz
    > > >>
    > > >>
    > > >> "rodchar" wrote:
    > > >>
    > > >>> hey all,
    > > >>> i'm inside a RowDataBound event and i'd like to dynamically add a button to
    > > >>> an empty gridView column with a click event handler. i'm having trouble with
    > > >>> wiring my procedure to the btn click event.
    > > >>>
    > > >>> protected void GridView1_RowDataBound(object sender,
    > > >>> GridViewRowEventArgs e)
    > > >>> {
    > > >>> if (e.Row.RowType == DataControlRowType.DataRow)
    > > >>> {
    > > >>> Button btn = new Button();
    > > >>> btn.Click += ??? (trying to get the method below to run)
    > > >>>
    > > >>> e.Row.Cells[2].Controls.Add(btn);
    > > >>> }
    > > >>> }
    > > >>> protected void BtnClickEventHandler(object sender, EventArgs e)
    > > >>> {
    > > >>> Response.Write("It Worked.");
    > > >>> }
    > > >>>
    > > >>> any ideas?
    > > >>> thanks,
    > > >>> rodchar

    > >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Feb 8, 2007
    #6
  7. thanks everyone i appreciate the help.

    "rodchar" wrote:

    > hey all,
    > i'm inside a RowDataBound event and i'd like to dynamically add a button to
    > an empty gridView column with a click event handler. i'm having trouble with
    > wiring my procedure to the btn click event.
    >
    > protected void GridView1_RowDataBound(object sender,
    > GridViewRowEventArgs e)
    > {
    > if (e.Row.RowType == DataControlRowType.DataRow)
    > {
    > Button btn = new Button();
    > btn.Click += ??? (trying to get the method below to run)
    >
    > e.Row.Cells[2].Controls.Add(btn);
    > }
    > }
    > protected void BtnClickEventHandler(object sender, EventArgs e)
    > {
    > Response.Write("It Worked.");
    > }
    >
    > any ideas?
    > thanks,
    > rodchar
    =?Utf-8?B?cm9kY2hhcg==?=, Feb 9, 2007
    #7
    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. Piero Massari

    tool to make a class diagram from csharp

    Piero Massari, Jun 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    517
    Sahil Malik
    Jun 17, 2004
  2. Natty Gur
    Replies:
    0
    Views:
    416
    Natty Gur
    Jul 27, 2003
  3. CSDunn

    ASP.NET not processing CSharp code

    CSDunn, Jan 7, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    427
    CSDunn
    Jan 14, 2004
  4. Vili
    Replies:
    1
    Views:
    573
    Eric Cherng
    Jun 28, 2004
  5. John
    Replies:
    1
    Views:
    3,219
    Scott Allen
    Jul 26, 2004
Loading...

Share This Page