protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//不遍历行头和行尾
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='LightSkyBlue'");//鼠标移入显示的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ced7f7'");//鼠标移出显示的颜色
//这里就是你要的效果
e.Row.Cells[2].ToolTip = e.Row.Cells[2].Text;
if (e.Row.Cells[2].Text.Length > 40)
{
e.Row.Cells[2].Text = e.Row.Cells[2].Text.Substring(0, 40) + "...";
}
e.Row.Cells[1].ToolTip = e.Row.Cells[1].Text;
if (e.Row.Cells[1].Text.Length > 8)
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 8) + "...";
}
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)//不遍历行头和行尾
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='LightSkyBlue'");//鼠标移入显示的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ced7f7'");//鼠标移出显示的颜色
//这里就是你要的效果
e.Row.Cells[2].ToolTip = e.Row.Cells[2].Text;
if (e.Row.Cells[2].Text.Length > 40)
{
e.Row.Cells[2].Text = e.Row.Cells[2].Text.Substring(0, 40) + "...";
}
e.Row.Cells[1].ToolTip = e.Row.Cells[1].Text;
if (e.Row.Cells[1].Text.Length > 8)
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 8) + "...";
}
}
}