Dynamically Hyperlink and Event Handler for the Hyperlink ?

K

Ken

Hi,

I´m creating an Hyperlink dynamically for my DataGrid:


HyperLink hl = new HyperLink();
hl.Text = "MyLink";
hl.NavigateUrl = "#";
e.Item.Cells[3].Controls.Add(hl);

When the user clicks that HyperLink, instead of sending to an specified URL
in the
NavigateUrl, example : hl.NavigateUrl = http://www.site.com; I want to
'catch' the
click event and call a Method instead

private void MyMethod()
{
// do something here!
}

Any ideas for that?
Ken.
 
A

Alvin Bruney

you need to add this line when you generate your control
hl.Click +=new EventHandler(MyMethod);

your mymethod must be declared like this to match the click event delegate

private void MyMethod(object sender, System.EventArgs e)
 

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,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top