用GRIDVIEW绑定数据库里面的某个字段因为这个字段内容太多 想只绑定前几个字 然后点击看详细内容 应该怎么做啊?怎么才能绑定前几个字 像这样“csdn...”
模板列
<itemtemplate>
<asp:Label runat='server' id='lbl1' Text='<%# Eval("MyField") %> '></asp:Label>在RowItemBound事件里写
Label lbl = (Label)e.row.findControl("lbl1");
string str = lbl.Text;
if(str.Length > 10)
{
lbl.Text = str.Substring(0, 10) + ".....";
lbl.tooltip= str;
}上面这段代码 老提示“未将对象引用设置到对象的实例。”string str = lbl.Text;
哪不对啊
模板列
<itemtemplate>
<asp:Label runat='server' id='lbl1' Text='<%# Eval("MyField") %> '></asp:Label>在RowItemBound事件里写
Label lbl = (Label)e.row.findControl("lbl1");
string str = lbl.Text;
if(str.Length > 10)
{
lbl.Text = str.Substring(0, 10) + ".....";
lbl.tooltip= str;
}上面这段代码 老提示“未将对象引用设置到对象的实例。”string str = lbl.Text;
哪不对啊
.clip_text
{
text-overflow:ellipsis; white-space:nowrap; overflow:hidden;
}可以自动剪去多余字符,并显示...
if(e.Row.Rowtype=DataControlRowType.dataRow)
{
.....
}
似乎 firefox 中不好用..
也可以实现,就是麻烦些
http://www.aoao.org.cn/blog/2008/07/firefox-text-overflow-ellipsis/
使用text-overflow是按px计算,很精确看楼主自己取舍了