0

这是 GridView :

<asp:GridView ID="grdProduct" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="sdsProducts" OnSelectedIndexChanged="grdProduct_SelectedIndexChanged" Width="1000px" BackColor="White" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" Font-Names="Arial" Font-Underline="False" ForeColor="Black">
<AlternatingRowStyle VerticalAlign="Middle" />
<Columns>
    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID"/>
    <asp:BoundField DataField="Name" HeaderText="Nom" SortExpression="Name" />
    <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/dataG/cancel.png" DeleteImageUrl="~/Images/dataG/delete.png" EditImageUrl="~/Images/dataG/edit.png" InsertImageUrl="~/Images/dataG/insert.png" ShowEditButton="True" UpdateImageUrl="~/Images/dataG/update.png" />
    <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/dataG/cancel.png" DeleteImageUrl="~/Images/dataG/delete.png" EditImageUrl="~/Images/dataG/edit.png" InsertImageUrl="~/Images/dataG/insert.png" ShowDeleteButton="True" UpdateImageUrl="~/Images/dataG/update.png" />
    </Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" Font-Underline="False" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Center" VerticalAlign="Middle" />
<RowStyle HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />

它给了我这个结果:

--------------------------------
|ID | Name |         |          |
--------------------------------
|  1 | x     | Edit   | Delete|
|  2 | y     | Edit   | Delete|
|  3 | z     | Edit   | Delete|
--------------------------------

但我希望它是这样的:

--------------------------------
|ID | Name |       Action      |
--------------------------------
|  1 | x     | Edit     Delete|
|  2 | y     | Edit     Delete|
|  3 | z     | Edit     Delete|
--------------------------------

谢谢 :D

4

1 回答 1

0

您可以使用一个带有 HeaderText = "Action" 的 TemplateField 来执行此操作,而不是使用两个 CommandField。在 TemplateField 中,您可以将按钮添加为常规元素。

于 2015-04-19T15:34:22.213 回答