C# asp.net中的绑定字段中未设置gridview列宽
我需要设置第一列宽度的最大大小,但没有设置。在提供更多数据的同时,它也在不断扩展C# asp.net中的绑定字段中未设置gridview列宽,c#,css,asp.net,gridview,C#,Css,Asp.net,Gridview,我需要设置第一列宽度的最大大小,但没有设置。在提供更多数据的同时,它也在不断扩展 <div style="width:640px"> <table style="width:640px"> <asp:GridView ID="gvChallan" runat="server" AutoGenerateColumns="false" HeaderStyle-BackColor="#cccccc" Width="646px" > <
<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>
使用
标题样式宽度
代替项目样式宽度
,如下所示。还可以设置栅格本身的全宽
<asp:BoundField DataField="itemsdescription" HeaderText="Items/ Description" HtmlEncode="false" HeaderStyle-Width="222px" />
首先,你为什么有
?
将生成它在表上的标记,您将为此创建警告/问题
您已经定义了希望div标记占用的宽度。因此,不需要为GridView指定相同的值。将GridView的宽度设置为100%。将您的第一列设置为80%。因此,您的列宽将分别为80%、10%和10%。您必须为所有列定义一个宽度,以便尊重这些值;例如,对于三列网格,请在gridview的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;";
}
希望这对某人有所帮助。
这也可以使用。在每一列上,您必须指定自己的宽度。要在designer中执行此操作,请单击智能标记>编辑列>选择列,然后在属性列表中转到HeaderStyle>Width并将其设置为222px。