日期:2014-05-17 浏览次数:20476 次
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 = 0; 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(70); } } } } }
------解决方案--------------------
前台就是这样子了
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderStyle-Width="200px" HeaderText="第一列">
<ItemTemplate>
这是第一列
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="50px" HeaderText="第二列">
<ItemTemplate>
这是第二列
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台设置宽度,就是4楼了,支持4楼。