现在我用gridview绑定到数据库,但是有一列很长,有没有办法实现当绑定的时候显示前面几个字,当鼠标放上去的时候显示全部内容,郁闷阿

来源:互联网 发布:Linux按分钟生成日志 编辑:程序博客网 时间:2024/05/01 05:24
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) + "...";

}
}
}