Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

changing the forecolor of a hyperlink of a datagrid

Hi,

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

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", "this.style.color='#FF0000'")
           e.Item.Cells(7).Attributes.Add("onmouseout", "this.style.color='Purple'")
           End If

i tried this.style.ForeColor also..it 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??

Thanks,
Pra4444
0
Pra4444
Asked:
Pra4444
  • 2
  • 2
1 Solution
 
praneethaCommented:
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 vb.net this is C#
           testh.Attributes.Add("onmouseover", "this.style.color='#FF0000'")
            tesh.Attributes.Add("onmouseout", "this.style.color='Purple'")
           End If

try that
0
 
Pra4444Author Commented:
Hi,

On what event would i write that too??

example::: Item_Created, or Item_DataBound??


Thanks,
Pra4444
0
 
tusharashahCommented:
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", "this.style.color='#FF0000'")
           ( (HyperLink) e.Item.Cells(7).controls(0) ).Attributes.Add("onmouseout", "this.style.color='Purple'")
End If

-tushar
0
 
Pra4444Author Commented:
it works perfectly..thanks...

Pra4444
0
 
praneethaCommented:
yesh it shoul dbe inside ItemDataBound
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now