New event not firing

D

David

Hi all,

I am dynamically creating a LinkButton in my datagrid, however, the event
that I am creating for it is not firing.

I am obviously missing something? What am I missing?

Here is the code in my datagrid ItemDataBound


LinkButton MyButton = new LinkButton();
MyButton.Text = DataBinder.Eval(DI, "DFES Number").ToString();
MyButton.Command += new CommandEventHandler(this.Stats_Link_Click);
MyButton.CommandName = "StatsGrid_Button_Click";
MyButton.CommandArgument = DataBinder.Eval(DI, "DFES
Number").ToString();
e.Item.Cells[0].Controls.Add(MyButton);


I have a Stats_Link_Click event, but it is not firing.

Thanks for any help.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
K

Karl Seguin

Make sure to create this linkbutton and hook up the event on postback before
or during page_load. My guess is that you are creating this on initial
load, but not during postback.

Karl
 
S

S. Justin Gengo

David,

Actually, I think the problem is a different one. When a control is
contained inside of another, like your button being contained inside of your
datagrid, you can't hook up an event directly to it.

Instead on post back you'll need to figure out which of the rows in the
datagrid was clicked. I have very similar sample code on my web site,
www.aboutfortunate.com where I am showing how to add a checkbox to a
datagrid and then see which checkbox was checked. The code to figure out
which button was clicked will be almost identical.

If you click the "Code Library" link at the top of my site and then use the
search box that will appear on the page to search for "Checkbox in Datagrid"
you will find the code sample you need.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Karl Seguin said:
Make sure to create this linkbutton and hook up the event on postback
before or during page_load. My guess is that you are creating this on
initial load, but not during postback.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


David said:
Hi all,

I am dynamically creating a LinkButton in my datagrid, however, the event
that I am creating for it is not firing.

I am obviously missing something? What am I missing?

Here is the code in my datagrid ItemDataBound


LinkButton MyButton = new LinkButton();
MyButton.Text = DataBinder.Eval(DI, "DFES Number").ToString();
MyButton.Command += new CommandEventHandler(this.Stats_Link_Click);
MyButton.CommandName = "StatsGrid_Button_Click";
MyButton.CommandArgument = DataBinder.Eval(DI, "DFES
Number").ToString();
e.Item.Cells[0].Controls.Add(MyButton);


I have a Stats_Link_Click event, but it is not firing.

Thanks for any help.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top