Dynamically Hyperlink and Event Handler for the Hyperlink ?

Discussion in 'ASP .Net Datagrid Control' started by Ken, Aug 14, 2003.

  1. Ken

    Ken Guest

    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.
     
    Ken, Aug 14, 2003
    #1
    1. Advertising

  2. Ken

    Alvin Bruney Guest

    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)

    "Ken" <> wrote in message
    news:#...
    > 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.
    >
    >
    >
     
    Alvin Bruney, Aug 16, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jose Suero
    Replies:
    2
    Views:
    9,462
    Jose Suero
    Dec 26, 2003
  2. =?Utf-8?B?QW5kcmV3IFdpZWQ=?=

    Adding event handler for dynamically created controls

    =?Utf-8?B?QW5kcmV3IFdpZWQ=?=, Apr 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,423
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 25, 2004
  3. Replies:
    1
    Views:
    755
    Damien
    Feb 22, 2007
  4. Elton Wang

    Hyperlink Column Event Handler...

    Elton Wang, Feb 9, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    162
    Elton Wang
    Feb 9, 2005
  5. Adi
    Replies:
    2
    Views:
    206
Loading...

Share This Page