ASP.NET WebForms - 如何在 GridView 中设置标题行的 colspan?

标签 asp.net gridview webforms

我想为 GridView 中的标题行设置 colspan,使其看起来与下图相同:

alt text

HTML 代码为:

<html>
    <body>
        <table border="1">
        <tr>
            <th colspan=2>Header</th>
        </tr>
        <tr>
            <td>row 1, cell 1</td>
            <td>row 1, cell 2</td>
        </tr>
        <tr>
            <td>row 2, cell 1</td>
            <td>row 2, cell 2</td>
        </tr>
        </table>
    </body>
</html>

我不知道如何在 asp.net 中创建相同的效果,并且我不想使用 for 循环手动创建表格。

谢谢!

最佳答案

我附加到 PreRender 事件:

protected void GridView1_PreRender(object sender, EventArgs e)
{
    var gridView = (GridView) sender;
    var header = (GridViewRow) gridView.Controls[0].Controls[0];

    header.Cells[0].Visible = false;
    header.Cells[1].ColumnSpan = 2;
    header.Cells[1].Text = "Header";
}

关于ASP.NET WebForms - 如何在 GridView 中设置标题行的 colspan?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3966078/

相关文章:

asp.net - 如何将 imagebutton 链接到 url 视觉 Web 开发人员

android - 如何在 Android GridView 中设置单元格大小?

javascript - ASP.Net、JavaScript 中 GridView 上的线条

asp.net-mvc - 具有相同 MachineKey 的 ASP.NET MVC 和 Webforms 应用程序之间的 OWIN 身份验证 cookie 共享

c# - 强制加载整页

c# - ObjectContext 实例已被释放,不能再用于需要连接的操作。在引用表中

C# Entity Framework 延迟加载未加载

c# - 匿名类型的 Asp.net WebForms 错误

c# - 在 asp.net 中获取动态创建控件的属性值

c# - List<Tuple<T1,T2>> 作为 GridView 的数据源