2011-09-28 6 views
0

아래 코드는 잘 작동하지만 다음과 같은 유일한 문제는 backgroundColor='white'과 대체 행을 대체합니다. onmouseout을 사용할 때 대체 원색을 사용할 수 있습니까? 나는 그것을 얻지 않는다호버링 할 때 orgianl backgroundColor를 보존하는 방법은 무엇입니까?

<AlternatingRowStyle BackColor="#DEEEE9" Font-Size="8pt" /> 

if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'"); 
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'"); 
    e.Row.Attributes.Add("style", "cursor:pointer;"); 
} 

답변

0

당신은 정확히 onmouseout에 복원해야 무슨 색깔을 지정할 수 있습니다

if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
    string bgcolor = "white" 
    if (e.Row.RowState == DataControlRowState.Alternate) 
    { 
     bgcolor = "#DEEEE9"; 
    } 

    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'"); 
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + bgcolor + "'"); 
    e.Row.Attributes.Add("style", "cursor:pointer;"); 
} 
+0

Thanks Samich .... –

+0

왜 스타일 시트 기능이 내장되어 있는지 사용하는 대신이 작업을 수행하십시오. CSS 클래스는 hover 요소가 포함 된 기능을 제공하기도합니다. –

0

, 왜 그냥 "e.Row.Attributes.Add을하지 (" ","onmouseout this.style.backgroundColor = '흰색' '); " 원본 대체 색상으로 설정하시오 ???

+0

강조 표시 색은 그대로 유지되고 다른 행이 마우스 오버 될 때 되돌아 가지 않습니다. 그것은 단지 '호버'일 때 '선택'을 보여줍니다. –

0

이 같은 것을보십시오 :이 훨씬 적은 코드와 잘 작동

var color = "<%=System.Drawing.ColorTranslator.ToHtml(GridView1.AlternatingRowStyle.BackColor)%>"; 
0

. backgroundColor를 설정하기 전에 mouseover에서 사용자 정의 속성을 생성하고 마우스 밖으로 사용합니다. 행 색상을 번갈아 사용할 때 완벽하게 작동합니다.

row.Attributes["onmouseover"] = this.originalstyle=this.style.backgroundColor;this.style.cursor='hand';this.style.backgroundColor='#ffccff';"; 

row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.backgroundColor=this.originalstyle;"; 
관련 문제