gridview line selects to add colors and events

  • 2020-12-16 05:54:31
  • OfStack

In gridview list, you need to add the following effect, discoloration, if passed away back into the color of the before, when the rows selected by deepen color, to know which line is selected, especially the list when more data, mark is very important, trigger line selected events at the same time, so how do you select add color, at the same time also set out our event? If we bind e.Row.Attributes.Add ("onclick") twice and discover that only one of them can be triggered, we can actually put the other one into one

Here are some specific examples:
 
protected void EditGridview_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType== DataControlRowType.DataRow) 
{ 
// When the mouse is up   First, save the background color of the current row   And for the attached 1 color  
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='inactivecaptiontext',this.style.fontWeight='';this.style.cursor='hand';"); 
// When the mouse leaves   Restores the background color to the previous color  
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';"); 
// When the mouse is clicked, deepen the color flag  
e.Row.Attributes.Add("onclick", "setvalue();if(window.oldtr!=null){window.oldtr.runtimeStyle.cssText='';}this.runtimeStyle.cssText='background-color:#e6c5fc';window.oldtr=this"); 

} 


} 

js code:
 
<script type="text/javascript" > 
function setvalue() { 
alert(' The row clicks the event and changes color '); 
} 
</script> 

Related articles: