DataGrid 换行变色
前台
function mOver(src)
{
src.style.backgroundColor='dodgerblue'; src.style.cursor='hand';
}
//鼠标移开每行时触发事件
function mOut(src,type)
{
if(type==0)
{
src.style.backgroundColor='#ffffff';
}
else
{
src.style.backgroundColor='#CFE7FE';
}
src.style.cursor='auto';
}
后台
private void dg_KCCX_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)/
/绑定datagrid的事件,
{
if(e.Item.ItemIndex%2==1 && e.Item.ItemIndex!=-1)
{
e.Item.Attributes.Add("onmouseover","mOver(this);");
e.Item.Attributes.Add("onmouseout","mOut(this,1);");
e.Item.Cells[0].Attributes.Add("ondblclick","mClick(this.parentNode);");
e.Item.Cells[1].Attributes.Add("ondblclick","mClick(this.parentNode);");
e.Item.Cells[2].Attributes.Add("ondblclick","viewYBWL(this.parentNode);");
e.Item.Cells[3].Attributes.Add("ondblclick","mClick(this.parentNode);");
//e.Item.Cells[4].Attributes.Add("ondblclick","mClick(this.parentNode);");
}
else if(e.Item.ItemIndex%2!=1 && e.Item.ItemIndex!=-1)
{
e.Item.Attributes.Add("onmouseover","mOver(this);");
e.Item.Attributes.Add("onmouseout","mOut(this,0);");
e.Item.Cells[0].Attributes.Add("ondblclick","mClick(this.parentNode);");
e.Item.Cells[1].Attributes.Add("ondblclick","mClick(this.parentNode);");
e.Item.Cells[2].Attributes.Add("ondblclick","viewYBWL(this.parentNode);");
e.Item.Cells[3].Attributes.Add("ondblclick","mClick(this.parentNode);");
// e.Item.Cells[4].Attributes.Add("ondblclick","mClick(this.parentNode);");
}
}