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
> >
|