Link to home
Create AccountLog in
Avatar of MikeMCSD
MikeMCSDFlag for United States of America

asked on

Making the whole cell a Hyperlink when mouse is moved over it

I want to make this whole cell (column) a hyperlink, so when the mouse is moved over it,
the cell back color changes, and you can click any where in the cell to go to the link.

<asp:TemplateField ItemStyle-Width="35%">
<ItemTemplate>
<a href="ProductDetails.aspx?ProductId=<%#Eval("ProductId")%>" style="font-size:14px;">
<%#Server.HtmlEncode(Eval("Name").ToString())%>
</a>
</ItemTemplate></asp:TemplateField>

How can I do this? thanks
ASKER CERTIFIED SOLUTION
Avatar of SSupreme
SSupreme
Flag of Belarus image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of MikeMCSD

ASKER

thanks .  .

When I tried that, it only made the text of the cell change its back color, not the whole cell.

I tried this :

<asp:TemplateField ItemStyle-Width="35%" ItemStyle-CssClass="wholeCell">
<ItemTemplate>
<a href="ProductDetails.aspx?ProductId=<%#Eval("ProductId")%>" class="wholeCell" style="font-size:14px;" >
...

When I move the mouse over, the whole cell changes back color, but only the text has a clickable link.

Being this is a ASP.NET <asp:GridView>, it's hard to do these kind of things because you don't know what the
gridview is doing behind the scenes. Just have to experiment I guess.
Can you do it like follows?
 
<a href="ProductDetails.aspx?ProductId=<%#Eval("ProductId")%>" class="wholeCell" >
<asp:TemplateField ItemStyle-Width="35%">
<ItemTemplate>
<%#Server.HtmlEncode(Eval("Name").ToString())%>
</ItemTemplate></asp:TemplateField>
</a>

Open in new window

was thinking of trying that but figured the compiler wouldn't like that, and it didn't.
I'm guessing this is not possible to do with these templates in the grid view.
Just have to keep experimenting I guess.
Avatar of Deja Anbu
Try this:

Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
        For Each row As GridViewRow In GridView1.Rows
            row.Cells(1).Attributes("onmouseover") = "this.style.cursor='pointer';this.style.textDecoration='none';"
        Next
    End Sub

Open in new window

SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.