如何获取自定义gridview中第二个标题行中的事件
我需要向我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘿奈尔斯,
我们可以使用一些 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
试试这个。 合并 GridView/DataGrid 标头中的列
Try this. Merging columns in GridView/DataGrid header