日期:2014-05-18  浏览次数:20360 次

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

------解决方案--------------------
都这么麻烦,下面代码考过去,搞定
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) + "... ";

}
}
}