如何使用gridview的colspan

时间:2013-04-26 12:11:40

标签: c# asp.net gridview html-table

我正在尝试使用asp.net制作网格视图。我希望列的标题有一个像这样的colspan:

enter image description here

但就目前而言:

enter image description here

我的代码是:

<asp:GridView ID="GV" runat="server" AutoGenerateColumns="false" OnPreRender="gridView_PreRender">

            <Columns>

                <asp:BoundField HeaderText="" />
                <asp:BoundField HeaderText="Num OF" DataField="cod_wo" />
                <asp:BoundField HeaderText="Num Seq" DataField="dat_sequence" />
                <asp:BoundField HeaderText="Article" DataField="article"/>
                <asp:BoundField HeaderText="Qté OF Prévue" DataField="wo_qty" />
                <asp:BoundField HeaderText="Qté OF Revue" DataField="qty_revue" />
                <asp:BoundField HeaderText="Composant" DataField="composant" />
                <asp:BoundField HeaderText="Restant à assigner" DataField="restant_a_assigner" />
                <asp:BoundField HeaderText="Assignation HU" />
                <asp:BoundField HeaderText="Qté totale" DataField="qte_totale_assignee" />
                <asp:BoundField HeaderText="Num HU" DataField="num_hu" />
                <asp:BoundField HeaderText="Qté" DataField="qte_assignee" />

            </Columns>

        </asp:GridView>

在C#后面的代码中我有:

public static void MergeColumns(GridView gridView)
        {
            gridView.HeaderRow.Cells[0].RowSpan = 2;
            gridView.HeaderRow.Cells[1].RowSpan = 2;
            gridView.HeaderRow.Cells[2].RowSpan = 2;
            gridView.HeaderRow.Cells[3].RowSpan = 2;
            gridView.HeaderRow.Cells[4].RowSpan = 2;
            gridView.HeaderRow.Cells[5].RowSpan = 2;
            gridView.HeaderRow.Cells[6].RowSpan = 2;
            gridView.HeaderRow.Cells[7].RowSpan = 2;

            gridView.HeaderRow.Cells[8].ColumnSpan = 3;

        }
你知道吗?感谢

1 个答案:

答案 0 :(得分:0)

您可以使用网格视图的 RowCreated 事件。为了更好地理解,请按照This Link

希望它能解决你的问题。