Adding onmouseover event to GridView's LinkButton

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RobertTheProgrammer
    New Member
    • Aug 2007
    • 58

    Adding onmouseover event to GridView's LinkButton

    Hi,

    On an ASP.NET GridView, I have several LinkButton objects. I want to add the "onmouseove r" event to the LinkButton so that I can perform a javascript task-- in particular, to rewrite the window.status message so it shows a more meaningful message than the layman-confusing javascript link message.

    So how do I add this "onmouseove r" event to the LinkButton? I'm stumped.

    Thanks.

    Robert
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by RobertTheProgra mmer
    Hi,

    On an ASP.NET GridView, I have several LinkButton objects. I want to add the "onmouseove r" event to the LinkButton so that I can perform a javascript task-- in particular, to rewrite the window.status message so it shows a more meaningful message than the layman-confusing javascript link message.

    So how do I add this "onmouseove r" event to the LinkButton? I'm stumped.

    Thanks.

    Robert
    I can't remember if you are coding in C# or VB.NET.

    One way to solve this would be to implement the ITemplate class to customize a Template to be used for your GridView. If you don't have the time to learn how to do this...

    In your GridView's RowDataBound event you can set the LinkButton's onmouseover event.....
    [code=vbnet]
    Dim lbtnAs LinkButton
    'if the row is a data row, grab the link button and set it's properties
    If e.Row.RowType = DataControlRowT ype.DataRow Then
    'The CType() method casts the object retrieved by the FindControl to a LinkButton object
    lbtnAs = CType(e.Row.Fin dControl("theLi nkButtonControl Name"),LinkButt on)
    'As long as a LinkButton was returned...set the JavaScript
    If Not lbtnAs Is Nothing Then
    lbtnAs .Attributes.Add ("onmouseove r", "JavaScript:myJ avaScriptFuncti on()")
    End If
    End If
    [/code]

    Don't forget that LinkButtons have ToolTips...you could just set the LinkButton's ToolTip property to display additional information about said LinkButton instead ...
    [code=vbnet]
    Dim lbtnAs LinkButton
    'if the row is a data row, grab the link button and set it's properties
    If e.Row.RowType = DataControlRowT ype.DataRow Then
    'The CType() method casts the object retrieved by the FindControl method into a LinkButton
    lbtnAs = CType(e.Row.Fin dControl("theLi nkButtonControl Name"),LinkButt on)
    'As long as a LinkButton was returned...set the ToolTip
    If Not lbtnAs Is Nothing Then
    lbtn.ToolTip="A dditional information that is displayed when moused over the link button"
    End If
    End If
    [/code]

    Cheers!

    -Frinny

    Comment

    • RobertTheProgrammer
      New Member
      • Aug 2007
      • 58

      #3
      It's a thing of beauty!

      The code behind is in C#, but that's okay as I was able to adapt your suggestions.

      On the RowDataBound event, I have code like this:

      Code:
      LinkButton AddButton = (LinkButton)e.Row.FindControl("lnkAdd");
      if (AddButton != null) AddButton.Attributes.Add("onmouseover", "window.status='Click to insert a new record'; return true;");
      Works great. Thank you very much for taking the time to reply. It's very much appreciated.

      Robert

      Comment

      Working...