设置GridView 宽度无效
代码如下:GridView_busi_stat_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Width = 100;
}
}
还是不管用;还试过Columns[i].ItemStyle.Width也不管用。
不知道为什么
--------------------编程问答-------------------- 在前台写吧,活手工设置,看看行不行 --------------------编程问答-------------------- 必须要在后台设置吗?前台设置好不行吗? --------------------编程问答-------------------- 要设置表头,你那设置是记录 --------------------编程问答-------------------- 前台这样写的,也不行
<asp:BoundField DataField="item" HeaderText="" ReadOnly="True" >
<HeaderStyle Height="10px" Width="500px" />
<ItemStyle Height="10px" Width="500px" />
</asp:BoundField>
<asp:BoundField DataField="mth1_num" HeaderText="笔数" >
<ItemStyle Width="500px" />
</asp:BoundField> --------------------编程问答-------------------- 不可能吧!~~~看下你的GridView是怎么定义的,有没有设成100%的长度呀!~~ --------------------编程问答-------------------- <ItemStyle Width="100px" />
如果不行,看看你的《table》中长度是多少,会不会超过了中长度。
--------------------编程问答-------------------- gridview长宽设置无效是因为你设置了CellPadding="" CellSpacing="".把这个去掉试试 --------------------编程问答-------------------- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
...{
if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate) || e.Row.RowState == DataControlRowState.Edit)
...{
TextBox curText;
for (int i = 2; i < e.Row.Cells.Count; i++)
...{
if (e.Row.Cells[i].Controls.Count != 0)
...{
curText = e.Row.Cells[i].Controls[0] as TextBox;
if (curText != null)
...{
curText.Width = Unit.Pixel(50);
}
}
}
}
}
这里的DataControlRowState是个枚举,其值分别为0,1,2,4,8分别对应着二进制的值为0,1,10,100,1000,这样这些枚举值按位或就可以得到并列值
--------------------编程问答-------------------- --------------------编程问答-------------------- 历史的经验再一次告诉我们,这种问题往往是一些低级错误造成的,请楼主细看你自己的html。
补充:.NET技术 , ASP.NET