I have a 'status' cluster of three columns. I want to have the header row span all three. I know I can use the colspan="3" parameter with the th tag in HTML. How do I accomplish this with BoundField?

Sample code snippet as it exists now...

<asp:BoundField DataField="Priority" HeaderText="Priority" />
<asp:TemplateField ItemStyle-Width="50">
  <ItemTemplate>
    <asp:ImageButton ID="btnMinus" CommandName="minus" runat="server" ImageUrl="~/Images/arrowUp_ico.gif" BorderWidth="1" BorderStyle="Ridge" />
    <asp:ImageButton ID="btnPlus" CommandName="plus" runat="server" ImageUrl="~/Images/arrowDown_ico.gif" BorderWidth="1" BorderStyle="Ridge" />
  </ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProjectName" HeaderText="Project" />
<asp:BoundField DataField="Group" HeaderText="Group" />
<asp:BoundField DataField="Assigned" HeaderText="Assigned" />

...etc.

I need the header text 'Priority' to span the itself and the next two columns.

有帮助吗?

解决方案

As is usual for me, when it takes a long time to get an answer I figure it out myself. The solution is to go to the code behind in the init section (or equivalent, depending on your project) and add two lines...

myDataGrid.HeaderRow.Cells[n].ColumnSpan = 2;
MyDataGrid.HeaderRow.Cells[n+1].Visible = false;

This extends the first header cell (n) out to be two columns wide and removes the adjacent one. If you leave out the second line the header for that column just gets pushed to the right.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top