changing the forecolor of a hyperlink of a datagrid

Posted on 2004-10-08
Last Modified: 2010-05-18

I have created a hyperlink using a template column on a datagrid ...
<asp:TemplateColumn HeaderText="Report">
                  <asp:Hyperlink runat="server" Text='View Details' ForeColor="Purple" NavigateUrl='<%# "page.aspx?ViewID=" & Server.UrlEncode(Container.DataItem("datafield"))%>' ID="Hyperlink1"/>

Now..everything works fine..when i click on the hyperlink, it takes me to a new page..

what i want to do is when the user moves his mouse over the hyperlink, the forecolor of the hyperlink should change...i tried the following but it didnt work..
'If e.Item.ItemType = ListItemType.AlternatingItem Then
           e.Item.Cells(7).Attributes.Add("onmouseover", "'#FF0000'")
           e.Item.Cells(7).Attributes.Add("onmouseout", "'Purple'")
           End If

i tried didnt work..what i found out was, this was overridden by the forecolor attritbute that was set while displaying the hyperlink itself...
if so how would i implement the following??

Question by:Pra4444
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 15

Accepted Solution

praneetha earned 75 total points
ID: 12259585
If e.Item.ItemType <> ListItemType.Header && e.Item.ITemType<>ListItem.Footer Then
HyperLink tesh=(HyperLink) e.Item.Cells(7).FindControl("HyperLink1");//type cast this to Hyperlink in this is C#
           testh.Attributes.Add("onmouseover", "'#FF0000'")
            tesh.Attributes.Add("onmouseout", "'Purple'")
           End If

try that
LVL 12

Author Comment

ID: 12259649

On what event would i write that too??

example::: Item_Created, or Item_DataBound??

LVL 18

Expert Comment

ID: 12259671
Where do you have this code? It should be inside ItemDataBound Event:

If e.Item.ItemType = ListItemType.AlternatingItem Then
          ( (HyperLink) e.Item.Cells(7).controls(0) ).Attributes.Add("onmouseover", "'#FF0000'")
           ( (HyperLink) e.Item.Cells(7).controls(0) ).Attributes.Add("onmouseout", "'Purple'")
End If

LVL 12

Author Comment

ID: 12259714
it works perfectly..thanks...

LVL 15

Expert Comment

ID: 12259718
yesh it shoul dbe inside ItemDataBound

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question