前些天发了一篇 使用JavaScript选择GridView行的方法汇总(Select row of GridView by JavaScript)

 

有朋友反馈说不适用于DataGrid,确实,如果要在DataGrid的行中添加JavaScript事件捕捉,必须用下面的代码:

 

 

protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
 
if ( (e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item) )
 {
  e.Item.Style.Add(
"cursor""hand");
  e.Item.Attributes.Add(
"onmouseover""defColor=this.style.backgroundColor; this.style.backgroundColor='#BAE0F2';");
  e.Item.Attributes.Add(
"onmouseout""this.style.backgroundColor=defColor;");
 }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2022-02-04
  • 2021-09-28
  • 2022-12-23
  • 2021-05-26
  • 2021-07-29
  • 2022-12-23
相关资源
相似解决方案