截断gridview超出列宽的内容~~~在线急等

来源:百度知道 编辑:UC知道 时间:2024/04/27 23:08:21
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{

GridView1.Rows[i].Cells[8].Text = SubStr(GridView1.Rows[i].Cells[8].Text.ToString(), 10);

}

}
public string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr = sNewStr + "......";
return sNewStr;
}
用了这段代码,在正常列的情况下能实现该功能,可是我把该列该为了hyperlinfield后就什么都显示不出来了。帮忙解决下这个问题吧,很急,谢谢啦
还有能不能实现鼠标移上去出现所有内容

GridView1.Rows[i].Cells[8].Text = SubStr(GridView1.Rows[i].Cells[8].Text.ToString(), 10);
试下改成:
GridView1.Rows[i].Cells[8].Text = "<div style=\"width:100% overflow:hidden;\" onmouseover=\"this.style.overflow='auto'\">"+GridView1.Rows[i].Cells[8].Text+"<div/>"

没有测试过。

这些代码应该写在GridView1_RowDataBound事件里

((LinkButton)e.Row.Cells[8].FindControl("LinkButton的ID")).ToolTip = e.Row.Cells[8].Text;

if (e.Row.Cells[8].Text.Length > nLeng)
{
e.Row.Cells[8].Text = e.Row.Cells[8].Text.Substring(0, nLeng) + "...";
}

//绑定事件中
protected void grvParts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
//判断长度是否大于10
if (e.Row.Cells[6].Text.Length > 10)
{
//鼠标移上去出现所有内容