我有一个简单的GridView
启用了编辑,但是当我点击edit
按钮时,宽度不会包裹在包装器中。如何更改编辑模板的宽度?以下是基本代码和附图。
<asp:GridView ID="GridView2" runat="server" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="ztag" HeaderText="ztag" SortExpression="ztag" />
<asp:BoundField DataField="item" HeaderText="item" SortExpression="item" />
<asp:BoundField DataField="manu" HeaderText="manu" SortExpression="manu" />
<asp:BoundField DataField="model" HeaderText="model" SortExpression="model" />
<asp:BoundField DataField="serial" HeaderText="serial"
SortExpression="serial" />
<asp:BoundField DataField="location" HeaderText="location"
SortExpression="location" />
<asp:BoundField DataField="division" HeaderText="division"
SortExpression="division" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
答案 0 :(得分:1)
您可以将_RowEditing事件添加到Gridview,并在该代码中设置gridview列的宽度。
将其添加到gridview标记中。
OnRowEditing="GridView2_RowEditing"
这就在你的代码背后。
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView2.Columns[0].ItemStyle.Width = Unit.Percentage(20);
//etc>
}
如果它不能打球,请在Gridview的PreRender事件中进行。您可以设置变量以确定是否处于编辑模式,并设置所有列的宽度以适应。啊,我看到你很幸运,得到了某人的投票!