Объединить CommandFields ASP.NET
Это 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
1 ответ
Для этого вы можете использовать один TemplateField с HeaderText = "Action" вместо двух CommandFields. В TemplateField вы можете добавлять кнопки как обычные элементы.