如何获取自定义gridview中第二个标题行中的事件

发布于 2024-11-08 04:37:31 字数 1104 浏览 0 评论 0原文

我需要向我的 ASP.NET GridView 添加一个辅助(标题)行(它已经自定义,因此我可以访问事件生命周期的任何部分)。

这是我想要与某些列对齐的附加数据。

它应该看起来像这样,

Period    |  May  |  June | July | Aug      -- Header
Basevalue | 3000  | 1500  | 1200 | 4000     -- EXTERNAL DATA
---------------------------------------
Item 1    |  100  |  200  |  300 |  400    
Item 2    |  100  |  200  |  300 |  400      

我设法使用下面的代码添加一行,但我无法创建任何类型的自定义事件,在其中我可以获得访问权限并将自定义数据写入该单元格。我尝试了以下操作,但在我能找到的任何事件(如 OnRowCreated 或PrepareControlHierarchy)期间,要么为时已晚(在数据绑定之后),要么内表未初始化。

int rowIndex = 0;

GridViewRow secondHeaderRow = new GridViewRow(rowIndex, -1, DataControlRowType.Header, DataControlRowState.Normal);
secondHeaderRow.TableSection = TableRowSection.TableHeader;

foreach (DataControlField col in this.Columns)
            {
                TableHeaderCell cell = new TableHeaderCell();
                cell.DataBinding += new EventHandler(OnHeaderCellDatabinding);
                secondHeaderRow.Cells.Add(cell);
            }

 InnerTable.Rows.AddAt(rowIndex, secondHeaderRow);

如何连接 GridView 生命周期以在标题行中写入?

I need to add a secondary (header) row to my ASP.NET GridView (which is already customized so I can access any part of the event lifecycle).

It's additional data that I want aligned with some of the columns.

It should look like this

Period    |  May  |  June | July | Aug      -- Header
Basevalue | 3000  | 1500  | 1200 | 4000     -- EXTERNAL DATA
---------------------------------------
Item 1    |  100  |  200  |  300 |  400    
Item 2    |  100  |  200  |  300 |  400      

I managed to add a row with below code, but I am unable to create any kind of custom event where I could gain access and write my custom data into that cell. I tried the following, but during any event I could find (like OnRowCreated or PrepareControlHierarchy), it's either too late (after databinding) or the inner table is not initalized.

int rowIndex = 0;

GridViewRow secondHeaderRow = new GridViewRow(rowIndex, -1, DataControlRowType.Header, DataControlRowState.Normal);
secondHeaderRow.TableSection = TableRowSection.TableHeader;

foreach (DataControlField col in this.Columns)
            {
                TableHeaderCell cell = new TableHeaderCell();
                cell.DataBinding += new EventHandler(OnHeaderCellDatabinding);
                secondHeaderRow.Cells.Add(cell);
            }

 InnerTable.Rows.AddAt(rowIndex, secondHeaderRow);

How can I hook up to the GridView lifecycle to write in the header row?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉南桥 2024-11-15 04:37:31

嘿奈尔斯,
我们可以使用一些 HTML 标签的标题并开始构建额外的标头,

请参阅此链接来解决您的问题

点击这里

希望对您有帮助

hey niles,
we can use the caption to some HTML tags and start building the extra headers

please refer this link for your problem

CLICK HERE

hope it will help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文