webform中GridView怎么实现固定列宽,多余的数据就显示为...,象winform的dataGridView一样,双击显示全部数据? 如题。最好能有代码,目前研究vb.net,c#也行。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 c#中,gridview列宽可以在gridview中的列的属性中可以设定。 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { //读取相关信息7个字符显示,这里是对第二列数据处理 string str =e.Row.Cells[1].Text; //显示详细信息 e.Row.Cells[1].ToolTip = str;//这个可以在鼠标放在这列上,就会显示详细的这列的内容 // if (str.Length >= 7) { e.Row.Cells[1].Text = str.Substring(0,7)+"<strong>...</strong>"; }}上面的代码对中文处理,可能有时会取半个字符,所以还要优化一下。 for (int i = 0; i < GridView1.Rows.Count; i++) { for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++) { string s = GridView1.Rows[i].Cells[j].Text; string t = s; if (s.Length >= 10) { t = s.Substring(0, 8) + ".."; } GridView1.Rows[i].Cells[j].Text = t; GridView1.Rows[i].Cells[j].ToolTip = t; GridView1.Rows[i].Cells[j].Attributes.Add("ondbclick", "this.innerText = this.title"); }} 最好的办法是从数据库取数据的时候就取固定长度.如:select id,left(content,10) from t_news;然后再通过DataSet绑定到控件上,这样又可以节省服务器资源. GridView1.Column[0].Style.Width="100px" DataTable dt = new DataTable(); dt.Columns.Add("abc", typeof(string)); DataRow dr = dt.NewRow(); dr[0] = "abccccccccccccccccccccccc"; dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); for (int i = 0; i < GridView1.Rows.Count; i++) { for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++) { string s = GridView1.Rows[i].Cells[j].Text; string t = s; if (s.Length >= 10) { s = s.Substring(0, 8) + ".."; } GridView1.Rows[i].Cells[j].Text =s ; GridView1.Rows[i].Cells[j].ToolTip = t; GridView1.Rows[i].Cells[j].Attributes.Add("onDblClick", "this.innerText = this.title"); } }测试了一下,db要分大小写. 淘宝 网页鼠标悬停图像变换问题 Gridview js事件的疑问 前台页面中使用js调用后台C#方法相关知识请教...... 求一javascript正则或者实现代码 救救我吧 excel 文件名过长无法下载 ,请问高手 问一下高手,OWC如何使用呢,我真的没有分了!谢谢 复选框实现批量删除的问题,求解! 提问:如何搭建一个asp.net的最简平台 ASP。NET 无法正常运行的疑问!谢各位高手! 使用ajax出现xmlHttp.readyState null 为空或不是对象 请教B/S结构的网络视频监控系统例子或思路
{
//读取相关信息7个字符显示,这里是对第二列数据处理
string str =e.Row.Cells[1].Text;
//显示详细信息
e.Row.Cells[1].ToolTip = str;//这个可以在鼠标放在这列上,就会显示详细的这列的内容
//
if (str.Length >= 7)
{
e.Row.Cells[1].Text = str.Substring(0,7)+"<strong>...</strong>";
}
}
上面的代码对中文处理,可能有时会取半个字符,所以还要优化一下。
{
for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++)
{
string s = GridView1.Rows[i].Cells[j].Text;
string t = s;
if (s.Length >= 10)
{
t = s.Substring(0, 8) + "..";
}
GridView1.Rows[i].Cells[j].Text = t;
GridView1.Rows[i].Cells[j].ToolTip = t;
GridView1.Rows[i].Cells[j].Attributes.Add("ondbclick", "this.innerText = this.title"); }
}
然后再通过DataSet绑定到控件上,这样又可以节省服务器资源.
GridView1.Column[0].Style.Width="100px"
dt.Columns.Add("abc", typeof(string));
DataRow dr = dt.NewRow();
dr[0] = "abccccccccccccccccccccccc";
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind(); for (int i = 0; i < GridView1.Rows.Count; i++)
{
for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++)
{
string s = GridView1.Rows[i].Cells[j].Text;
string t = s;
if (s.Length >= 10)
{
s = s.Substring(0, 8) + "..";
}
GridView1.Rows[i].Cells[j].Text =s ;
GridView1.Rows[i].Cells[j].ToolTip = t;
GridView1.Rows[i].Cells[j].Attributes.Add("onDblClick", "this.innerText = this.title"); }
}测试了一下,db要分大小写.