Recent Post

Saturday, May 4, 2013

Đổi màu Dòng Gridview khi rê chuột trong asp.net

by Unknown  |  at  12:08 PM



Cuối tuần rảnh nghịch chơi có cái đó nhìn cũng được thì up lên chơi

mở file đính kèm bằng sql 2008 và vs2010 nha.

bắt đầu bằng các chúng ta viết javascript cho gridview cần sự kiện :


<script type="text/javascript">

var lastColor;

function DG_changeBackColor(row, highlight) {

if (highlight) {

row.style.cursor = "hand";

lastColor = row.style.backgroundColor;

row.style.backgroundColor = 'yellow';

}

else

row.style.backgroundColor = lastColor;

}



</script>







sau đó gọi đến sự kiện RowDataBound của gridview cần đổi màu :





protected void gvw_danhsach_nhapma_bk1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if ((e.Row.RowType == DataControlRowType.Pager) || (e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.Footer))

{

return;

}

else

{

//Thêm sự kiện để thay đổi mày nền khi di chuyển con trỏ qua 1 dòng

e.Row.Attributes.Add("onmouseover", "DG_changeBackColor(this, true);");

e.Row.Attributes.Add("onmouseout", "DG_changeBackColor(this,false);");

// e.Row.Attributes.Add("onclick", "DG_changeBackColor(this,true);");

}

}




file đính kèm




sau khi làm xong được như hình :

0 comments:

Proudly Powered by Blogger.