csharp syntax help

G

Guest

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
 
G

Guest

Hi,

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

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

Guest

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 said:
Hi,

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

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


rodchar said:
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
 
B

bruce barker

you need re-add the handler on postback.

-- bruce (sqlwork.com)
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 said:
Hi,

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

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


rodchar said:
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
 
G

Guest

where would i do that at?

bruce barker said:
you need re-add the handler on postback.

-- bruce (sqlwork.com)
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 said:
Hi,

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

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


:

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
 
G

Guest

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 said:
where would i do that at?

bruce barker said:
you need re-add the handler on postback.

-- bruce (sqlwork.com)
For some reason the event is not firing when i click the button in the
gridview, what i am i missing?

thanks,
rodchar

:

Hi,

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

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


:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top