gridview绑定的标题列一行大概放20个汉字,如果多了自动换行,页面就不美观了怎么让标题需要换行的末尾显示省略号,鼠标移到那显示全部内容
解决方案 »
- 图片按钮onClick事件问题
- 非常急!!!我想问下,下面的代码究竟哪儿错了,我弄了很久啊,现在被老师批
- 上传文件的问题
- 为什么asp.net网站配置工具打不开?
- vb2003 中如何实现对 页面中 历遍 所有的 textbox 的ASP控件 进行 赋值 ??????? 急!!!!!!!!
- "Specified cast is not valid"这个异常谁遇到过?
- 请问每个程序员是怎样将程序模块化的,谢谢指点!
- 设置GridView 宽度无效
- 如何设置服务器控件同时属于两个ValidationGroup验证组?
- 请高手帮忙!!!!
- datatable如何取多行多列中的某一列某一行的值?
- 征求一下意见
鼠标移到那显示全部内容——————设置该单元格的title属性为标题内容;
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string sTmp;
string pic;
if (((DataRowView)e.Item.DataItem)["FileTitle"] != DBNull.Value)
{
sTmp = Convert.ToString(((DataRowView)e.Item.DataItem)["FileTitle"]);
pic = Convert.ToString(((DataRowView)e.Item.DataItem)["IsImage"]);
if (pic == "1")
{
string stmp2 = "";
if (sTmp.Length <= 19)
stmp2 = sTmp + "(图)";
if (sTmp.Length > 19)
stmp2 = sTmp.Substring(0, 18) + "…(图)";
sTmp = stmp2;
}
else
{
if (sTmp.Length > 21)
sTmp = sTmp.Substring(0, 20) + "…";
}
((HyperLink)e.Item.FindControl("hylzcwj")).Text = "˙" + sTmp; }
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if ((e.Row.Cells[i].Text != "") && (i == 5) && (e.Row.Cells[i].Text != null))
{
str = e.Row.Cells[i].Text;
e.Row.Cells[i].Text = cutStr(e.Row.Cells[i].Text, 20);
e.Row.Cells[i].Text = "<a style='cursor:hand;' title='" + str + "'>" + e.Row.Cells[i].Text + "</a>";
}
}
}
//devidefunction.cutStr是截取字符穿方法20代表只显示20个字符,这样就可以做到了
//*******************************文字截断加……函数*******************************
public static string cutStr(string str, int num)
{
if ((str.Length) > num)
{
str = " " + str.Substring(0, num) + "...";
return str;
}
else
{
return str;
}
}
截就行了.6楼的这个方法即可. public static string cutStr(string str, int num)
{
if ((str.Length) > num)
{
str = " " + str.Substring(0, num) + "...";
return str;
}
else
{
return str;
}
}
//解决方法:数据绑定后过滤每一行即可
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
DataRowView mydrv;
string gIntro;
if (GridView1.PageIndex == 0)
{
mydrv = myds.Tables["工作室"].DefaultView[i];//表名
gIntro = Convert.ToString(mydrv["家庭住址"]);//所要处理的字段
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
}
else
{
mydrv = myds.Tables["工作室"].DefaultView[i + (5 * GridView1.PageIndex)];
gIntro = Convert.ToString(mydrv["家庭住址"]);
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
}
} //调用的方法: public string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr = sNewStr + "...";
return sNewStr;
}
<tr>
<td width="100">
<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100px;" title="测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试">
测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试</div>
</td>
</tr>
</table>显示为: 测试测试测...
{
string str = e.Row.Cells[2].Text.Trim(); str="" 这是为什么?
e.Row.Cells[2].Text = cutStr(str, 40);
}
去看看
在模板列中将要显示的字段改成TextBox(只读,背景颜色透明,边框去掉),鼠标扫过可显示全部.
或再加toolTip属性!!
public static string CutString(string str, int num, bool flg)
{
#region
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
string tempString = "";
byte[] s = ascii.GetBytes(str);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
{
tempLen += 2;
}
else
{
tempLen += 1;
} try
{
tempString += str.Substring(i, 1);
}
catch
{
break;
} if (tempLen > num)
break;
}
//如果截过则加上半个省略号
byte[] mybyte = System.Text.Encoding.Default.GetBytes(str);
if (mybyte.Length > num)
if (flg)
{
tempString += "...";
}
return tempString;
#endregion
}
要吗用个过滤长度的函数然后使用在模板列中
要吗你设置一下那个属性让它自动换行