现在我用gridview绑定到数据库,但是有一列很长,有没有办法实现当绑定的时候显示前面几个字,当鼠标放上去的时候显示全部内容,郁闷阿 现在我用gridview绑定到数据库,但是有一列很长,有没有办法实现当绑定的时候显示前面几个字,当鼠标放上去的时候显示全部内容,郁闷阿 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 当然可以.在RowDataBound上写事件随手写点代码,也许有语法错误.int i;i=e.Argument....;string s;s=Gridview1.Rows[i].Cells[10].Text;if (s.length>10)Gridview1.Rows[i].Cells[10].Text=s.Substring(0,6)+"...";...... select substring(field,1,12)+'...' as field from table1 static public string Left(string str,int L) { string tmpStr; tmpStr=str; if(str.Length>L) { tmpStr=str.Substring(0,L)+".........."; } return tmpStr; } 引用: <%# Left(Convert.ToString(DataBinder.Eval(Container, "DataItem.tongzlr")),90) %> <a title='<%#Eval("ziduan").ToString() %>'><%#Eval("ziduan").ToString().Length > 5 ? Eval("ziduan").ToString().Substring(0, 5) : Eval("ziduan").ToString()%></a> 都这么麻烦,下面代码考过去,搞定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) + "..."; } } } 你把我那个里面的Index 改一下就行了,还有你要显示的长度的改一下,就OK了给分吧 jquery动态增加上传控件问题 关于宾客消费行为的分析器 FileUpLoad的样式修改问题!~~~ 如何读取XML下的所有节点? 怎样在前台实现数据库的备份和还原 从sqlserver中读出的binary字段,如何转换为byte[]类型? 菜鸟求助~~如何将一个页面中DataGrid的值传递给另一个页面,急,在线等!! GridView表导入Excel的问题 datagrid的删除 请问怎么在前台调用codebehind的方法? SqlDataReader取值的问题 asp.net c# 中用DES和TripleDES加密成功,但解密失败?请教!
在RowDataBound上写事件
随手写点代码,也许有语法错误.
int i;
i=e.Argument....;
string s;
s=Gridview1.Rows[i].Cells[10].Text;
if (s.length>10)
Gridview1.Rows[i].Cells[10].Text=s.Substring(0,6)+"...";
...
...
{
string tmpStr;
tmpStr=str;
if(str.Length>L)
{
tmpStr=str.Substring(0,L)+"..........";
}
return tmpStr;
}
引用:
<%# Left(Convert.ToString(DataBinder.Eval(Container, "DataItem.tongzlr")),90) %>
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) + "..."; }
}
}