嗨我有一个删除的命令字段,我给它一个DeleteImageURL,但我不知道如何更改它的高度和宽度并让它居中。
DeleteImageUrl = “〜/ IMG / error.png”
这是我的gridview:
<asp:GridView ID="gvOrderDetail" runat="server" AutoGenerateColumns="False" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" CellPadding="4" ForeColor="#333333" GridLines="None" Width="660px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField HeaderText="Action" ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/img/error.png" />
<asp:BoundField DataField="PartNumber" HeaderText="Part Number" />
<asp:BoundField DataField="Description" HeaderText="Description"></asp:BoundField>
<asp:BoundField DataField="Qty" HeaderText="Qty" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="Price" HeaderText="Price" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="ExtPrice" HeaderText="Ext Price" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
</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 :(得分:3)
您有一个Style
属性可用于此目的:
这通过强类型属性将css样式应用于数据项内的控件。这是一个如何使用它的例子......
<asp:GridView...>
<Columns>
<asp:CommandField ControlStyle-Width="16px" ControlStyle-Height="16px" />
</Columns>
</asp:GridView>
当然,这会将相同的样式应用于CommandField
中的所有控件,因此如果您在ShowEditButton=true
中指定ShowDeleteButton=true
和CommandField
,则删除和编辑按钮将共享相同的样式。最重要的是,如果你需要&#34;总计&#34;这可能有点受限。控制这些控制。
如果您需要为每个控件指定不同的样式,那么您应该使用TemplateField
而不是CommandField
答案 1 :(得分:0)
我想通了
ItemStyle-宽度=&#34; 25像素&#34;
最终守则:
<asp:GridView ID="gvOrderDetail" runat="server" AutoGenerateColumns="False" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" CellPadding="4" ForeColor="#333333" GridLines="None" Width="660px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField HeaderText="Action" ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/img/error.png" ItemStyle-Width="25px" />
<asp:BoundField DataField="PartNumber" HeaderText="Part Number" />
<asp:BoundField DataField="Description" HeaderText="Description"></asp:BoundField>
<asp:BoundField DataField="Qty" HeaderText="Qty" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="Price" HeaderText="Price" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="ExtPrice" HeaderText="Ext Price" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
</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>