Asp.net GridView合并标题单元格时生成的多余单元格和空数据行

问题描述

我正在尝试使用 ASPX标记代码中的合并标题行创建Gridview控件。 但是生成的Gridview(html表)显示了第一个额外的空行和第一个空单元格。细胞(0) 这弄乱了表的布局。

以下是示例 ASPX代码代码

     <asp:GridView ID="gv" runat="server"  GridLines="both"  AutoGenerateColumns="false">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <thead>
                                <th colspan="5" style="text-align: center; background: yellow;">Routine</th>
                                <tr style="background: lightblue;">
                                    <th>Sequence</th>
                                    <th>Excerise</th>
                                    <th>Time</th>
                                    <th>pulse</th>
                                    <th>Calories</th>
                                </tr>
                           </thead>
                        </HeaderTemplate>
                    </asp:TemplateField>
                    
                    <asp:BoundField datafield="Order"/>
                    <asp:BoundField datafield="TiMetaken"/>
                    <asp:BoundField datafield="Excerise"/>
                    <asp:BoundField datafield="pulse"/>
                    <asp:BoundField datafield="Calories"/>
                </Columns>
            </asp:GridView>

**这是HTML输出结果**

    <table cellspacing="0" rules="all" border="1" id="gv" style="border-collapse:collapse;">
        <tr>
            <th scope="col">
                <thead>
                    <th colspan="5" style="text-align: center; background: yellow;">Routine</th>
                    <tr style="background: lightblue;">
                        <th>Sequence</th>
                        <th>Excerise</th>
                        <th>Time</th>
                        <th>pulse</th>
                        <th>Calories</th>
                    </tr>
                </thead>
            </th>
            <th scope="col">&nbsp;</th>
            <th scope="col">&nbsp;</th>
            <th scope="col">&nbsp;</th>
            <th scope="col">&nbsp;</th>
            <th scope="col">&nbsp;</th>
        </tr>
                
                <tr>
            <td>&nbsp;</td><td>1</td><td>5</td><td>Warmup</td><td>70</td><td>50</td>
        </tr><tr>
            <td>&nbsp;</td><td>2</td><td>10</td><td>Walk</td><td>75</td><td>100</td>
        </tr><tr>
            <td>&nbsp;</td><td>3</td><td>5</td><td>Stetch</td><td>80</td><td>80</td>
        </tr><tr>
            <td>&nbsp;</td><td>4</td><td>10</td><td>Cardio</td><td>90</td><td>120</td>
        </tr><tr>
            <td>&nbsp;</td><td>5</td><td>20</td><td>CrossFit</td><td>110</td><td>500</td>
        </tr>
    </table>

您看到**多余的空标签吗?。 **不确定如何生成代码benind的简单数据源和数据绑定。

已附加图片HTML table output

有人可以让我知道这个问题吗? 我也许可以在RowDataBound事件中做到这一点,并且可以在单元格和属性中播放,但是我想在ASPX上做到这一点,因为它在设计时是简单的HTML和可视化。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)