一个 GridView 的小问题?? 我的 GridView 的宽度是 100% ,可是就有问题了,其中的一列中的内容是很长的,就导致整个 GridView 拉的很长(很难看)。那么我如何能设置此列:让此列每多少个字符就自动换行呢~~?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不用,设置一下列的宽度,给需要换行的列加上这个样式:style="word-wrap:break-word;word-break:break-all;"即可 在你的gridview 的 rowdatabound 中加入e.Row.Cells[2].Style.Add("word-break", "break-all"); e.Row.Cells[2].Width = 1024;e.Row.Cells[2] 是第三列 这就是给第三列加css e.Row.Cells[2].Width = 1024; 是说 宽度超过1024px 就换行 根据需要改下就好 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){ if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Wrap = true;//0可以改写别的列,换行启动 }} protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //e.Row.Cells[0].Wrap = true; or e.Row.Cells[0].Attributes.Add("word-break", "break-all") ; } } 各位在后台设置的方法我也试用了,怎么不好使牙~~ protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Wrap = true; e.Row.Cells[3].Attributes.Add("word-break", "break-all") ; e.Row.Cells[3].Width = 10; e.Row.Cells[4].Attributes.Add("word-break", "break-all"); e.Row.Cells[4].Width = 10; } } 给具体行由后面加个class, 通过css控制. GV的行宽是可以设置的,有个ControlStyle-Width属性设置下就可以了 如何用asp.net或者命令行,让COM+应用程序重新启动(急) 如何实现DetailsView控件插入模式内的模板字段赋值? 关于Label的小问题? 如何让下拉框在动态加载选项时让某些项满足一定条件时变色??? DataGrid能不能实现列的合并居中功能? 5秒一调用方法?????? 如何令鼠标移动到datagrid的某一行改变该行的底色? 紧急求助,asp.net的无名问题! sql server 连接的问题 下面的Insert语句哪里错了 修改membership字段类型问题 关于存储过程的返回值跟输入参数有什么不同
e.Row.Cells[2].Style.Add("word-break", "break-all");
e.Row.Cells[2].Width = 1024;e.Row.Cells[2] 是第三列
这就是给第三列加css e.Row.Cells[2].Width = 1024; 是说 宽度超过1024px 就换行
根据需要改下就好
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Wrap = true;//0可以改写别的列,换行启动
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Cells[0].Wrap = true; or
e.Row.Cells[0].Attributes.Add("word-break", "break-all") ; }
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Wrap = true;
e.Row.Cells[3].Attributes.Add("word-break", "break-all") ;
e.Row.Cells[3].Width = 10;
e.Row.Cells[4].Attributes.Add("word-break", "break-all");
e.Row.Cells[4].Width = 10;
}
}