asp.net Gridview data column

  • 2020-05-10 17:58:16
  • OfStack

Function description:
In gridview, as the mouse moves through the data list of the control, the background of the column changes the background color as the mouse moves.
Function realization:
Add an event RowDataBound in gridview, the code is as follows:
 
protected void gvwNews_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
e.Row.Attributes.Add("onmouseover", "color = this.style.backgroundColor;this.style.backgroundColor='#EAFCD5'"); 
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color"); 
e.Row.Attributes.Add("onclick", "ClickRow()"); 
} 
} 

The onclick event controls the selection of the check box at the beginning of the line, and clicking on the line gives you a "click" check box 1 effect. The code is as follows:
 
function ClickRow() 
{ 
var obj = event.srcElement.parentElement.firstChild.firstChild.tagName; 
alert(obj); 
if(obj!=null && obj.tagName+""!="undefined") 
{ 
obj.checked=obj.checked ? false : true; 
} 
} 

A few lines of code will do the trick.

Related articles: