Gridview自动列时怎么设置列宽度 Gridview中使用AutoGenerateColumns="true",也就是自动填充数据,所以弄的列名排放不好看,我想列不换行,这样就能自动调整宽度,为什么Gridview1.Columns[0] 找不到呀,希望大家帮我下,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 this.dataGridView1.Columns["印家"].Width = 120; 1. 自动生成的数据栏无法通过GridView.Columns访问到2. 如果希望表格中所有内容都不换行,那很容易,在表格属性中加上样式就行:<asp:GridView ID="GridView1" runat="server" style="white-space:nowrap" ... 3. 如果要对每一个列单独控制,那就要麻烦点,在GridView前面加上一段样式设定:<style type="text/css">#GridView1 tr td:first-child { width: 100px } /* 第一列 */#GridView1 tr td:first-child+td { width: 200px } /* 第二列 */#GridView1 tr td:first-child+td+td { width: 300px } /* 第三列 */</style>(注意如果table-layout不是fixed,列宽会自动调整,不一定会等于你设定的值)4. 上面这个方法只在IE7/8,FireFox下有效,如果要支持IE5/6,那就更麻烦了,可以考虑用jquery动态去设定列宽。 给你写一个吧 把下面的if语句写在 RowCreated事件里面! protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[0].Width = 480; e.Row.Cells[1].Width = 200; } } GridView1.Columns[1].HeaderStyle.Width = 200;for (int i = 0; i < GridView1.Columns.Count; i++) { GridView1.Columns[i].ItemStyle.Width = new Unit("100"); } 问一个定时操作的问题 后退的时候怎么让GridView的数据不改变呢 快来看看!取值问题 为什么找不到“添加业务服务引用” 大侠,快帮忙呀,在线等 怎么在asp.net显示星星 remoting下写配置文件的问题..... 关于从数据库中随机select的问题 如何读取dataset对象中一个表里一行中某一列的值? 通过自己计算机上的.net在别人的计算机创建工程文件怎么做到? 请教一个.net的时间函数 如何给DetailView控件的Delete事件加上一个确认对话框?
<asp:GridView ID="GridView1" runat="server" style="white-space:nowrap" ... 3. 如果要对每一个列单独控制,那就要麻烦点,在GridView前面加上一段样式设定:<style type="text/css">
#GridView1 tr td:first-child { width: 100px } /* 第一列 */
#GridView1 tr td:first-child+td { width: 200px } /* 第二列 */
#GridView1 tr td:first-child+td+td { width: 300px } /* 第三列 */
</style>(注意如果table-layout不是fixed,列宽会自动调整,不一定会等于你设定的值)4. 上面这个方法只在IE7/8,FireFox下有效,如果要支持IE5/6,那就更麻烦了,可以考虑用jquery动态去设定列宽。
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Width = 480;
e.Row.Cells[1].Width = 200;
}
}
{
GridView1.Columns[i].ItemStyle.Width = new Unit("100");
}