使用JavaScript选择DataGrid行的方法汇总(Select row of DataGrid by JavaScript)
前些天发了一篇 使用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;");
}
}
{
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;");
}
}