Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > csharp syntax help

Reply
Thread Tools

csharp syntax help

 
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      02-08-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
 
      02-08-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
 
      02-08-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
 
      02-08-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
 
      02-08-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
 
      02-08-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
 
      02-09-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

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
Help In Using Datagridview In Csharp jedlarosa General Computer Support 0 12-02-2009 12:10 AM
tool to make a class diagram from csharp Piero Massari ASP .Net 1 06-17-2004 09:14 PM
HOW TO: Create a single DataSet bound object used by 50 DropDownList box controls in the same web form. CSHARP Bill ASP .Net 3 03-01-2004 05:31 PM
ASP.NET not processing CSharp code CSDunn ASP .Net 5 01-14-2004 07:59 PM
Re: Project templatefor for ASP.NET in VB (Not CSharp), Natty Gur ASP .Net 0 07-27-2003 06:47 AM



Advertisments