2015-06-02 84 views
1

我有這樣的代碼:懸停時無法獲得文字以加下劃線?

e.Row.Attributes["onmouseover"] = "this.style.textDecoration='underline';"; 
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='';"; 

這應該這樣,當我將鼠標懸停在一排,在它的所有文本將帶有下劃線。但它不起作用。我也試過這個:

e.Row.Attributes.Add("onmouseover", "this.style.textDecoration='underline'"); 

哪一個也不行。

編輯:此代碼有效。是否有替代style.textDecoration類似於我可以使用,這不需要CSS?

e.Row.Attributes["onmouseover"] = "this.style.fontWeight='bold';"; 

回答

0

你可以使用,而此:

e.Row.Attributes.Add("class", "cell-hoverunderline");

,然後添加CSS樣式這樣:

.cell-hoverunderline:hover { 
    text-decoration: underline; 
} 
+0

這也不起作用。 – rustbird

1

你爲什麼不CSS代替?

.table-hover tr td:hover { 
    text-decoration: underline; 
} 
.table-hover tr td { 
    text-decoration: none; 
} 

然後應用類的表(我猜你正在使用的GridView):

<asp:GridView CssClass="table-hover"> 
    ..... 
</asp:GridView> 
+0

我的確嘗試過使用這樣的CSS,但是我無法正常工作。不過,我會試試你的例子並回復你! (是的,我正在使用GridView) – rustbird

+0

不,不起作用。 – rustbird

+0

你有什麼td元素?它可能有覆蓋風格。如果是的話,請在下劃線後重試!重要的是:'text-decoration:underline!important;'(注意:雖然這不是一個好習慣) –