网格视图列宽未在绑定字段中 asp.net 设置
本文关键字:字段 asp net 设置 绑定 视图 网格 | 更新日期: 2023-09-27 18:35:25
我需要设置第一列宽度的最大大小,但它没有设置。 同时放置更多数据,其扩展。
<div style="width:640px">
<table style="width:640px">
<asp:GridView ID="gvChallan" runat="server" AutoGenerateColumns="false" HeaderStyle-BackColor="#cccccc" Width="646px" >
<HeaderStyle Width="222px" />
<Columns>
<asp:BoundField DataField="itemsdescription" HeaderText="Items/ Description" HtmlEncode="false" HeaderStyle-Width="222px" />
<asp:BoundField DataField="Quantity" HeaderText="QTY" ItemStyle-Width="10%" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="center" />
<asp:BoundField DataField="TotalBoxes" HeaderText="Total Boxes" ItemStyle-Width="10%" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="center" />
</Columns>
</asp:GridView>
</table>
</div>
使用 HeaderStyle-Width
而不是 ItemStyle-Width
如下所示。还要设置网格本身的全宽
<asp:BoundField DataField="itemsdescription" HeaderText="Items/ Description" HtmlEncode="false" HeaderStyle-Width="222px" />
首先,你为什么有<table style="width:640px">
? <asp:GridView>
将生成它在表上的标签,您将为此创建警告/问题。
您已经定义了希望它使用div 标记占用的宽度。 因此,无需为 GridView 指定相同的值。将网格视图的宽度设置为 100%。 将第一列设置为 80%。因此,您的列宽为 80%、10% 和 10%。
您必须为所有列定义一个宽度,以便遵守这些值;例如,对于三列网格,请在网格视图的 RowDataBound 事件中尝试此操作:
protected void yourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Style.Value = "min-width:640px;";
e.Row.Cells[1].Style.Value = "min-width:200px;";
e.Row.Cells[2].Style.Value = "min-width:150px;";
}
希望这对某人有所帮助。