PC Review


Reply
Thread Tools Rate Thread

csharp syntax help

 
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      8th Feb 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      8th Feb 2007
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

 
Reply With Quote
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      8th Feb 2007
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

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      8th Feb 2007
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

 
Reply With Quote
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      8th Feb 2007
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

>

 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      8th Feb 2007
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

> >

 
Reply With Quote
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      9th Feb 2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generic Interface syntax in VS 2005 using Old syntax Saad Microsoft Dot NET 1 9th Jun 2009 02:43 PM
Generic Interface syntax in VS 2005 using Old syntax Saad Microsoft C# .NET 1 9th Jun 2009 06:43 AM
Re: HELP! UPDATE command tsql syntax and sql access syntax Bob Barrows [MVP] Microsoft Access Queries 5 27th Aug 2008 09:43 PM
Help with CSharp syntax [xxx()] and ~xxxx() ??? webmaster@1stmiami.com Microsoft C# .NET 1 30th Aug 2006 01:53 PM
msdn2 csharp docs are useless (no syntax/grammar) Microsoft C# .NET 3 14th Nov 2005 03:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:01 AM.