始终显示 FooterTemplate,即使没有数据
有没有一种简短的方法可以使 FooterTemplate(在 GridView 中)始终可见,即使 DataSource 为空?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有一种简短的方法可以使 FooterTemplate(在 GridView 中)始终可见,即使 DataSource 为空?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
我也遇到了这个问题。 来自 Alconja 的链接有很大帮助(感谢 Alconja),但 GridView.FooterRow 然后返回 null。 我需要它来从页脚插入新记录。
这是我最终有效的解决方案。 现在,即使网格为空,您也可以从页脚插入数据。
GridViewExtended.cs(App_Code 文件夹中的类):
在 aspx 页面中,只需添加
希望它对某人有帮助。
I was having trouble with this as well. The link from Alconja helps a lot (Thanks Alconja) but GridView.FooterRow then returns null. I need it for inserting new records from the footer.
This is my final solution that works. Now you can insert data from the footer even if the grid is empty.
GridViewExtended.cs (a class in the App_Code folder):
In the aspx page, simply add
and replace
<asp:GridView
with<YourPrefix:GridViewExtended
Hope it helps someone.
如果您希望它始终显示,无论内容如何,您不能将页脚 html 放在
GridView
之外,而不是放在FooterTemplate
中吗?如果由于某种原因这不是一个选项,那么您可以 如果数据源为空,则向其添加一个空行,或子类化 GridView & 覆盖默认行为。
这些是我所知道的唯一选项(尽管距离我上次使用 GridView 已经有一段时间了)。
If you want it to always display, regardless of content, can't you just put the footer html outside the
GridView
, instead of in theFooterTemplate
?If that's not an option for some reason, then you can either add an null row to your data source if it's empty, or subclass the
GridView
& override the default behaviour.Those are the only options I'm aware of (although its been a while since the last time I used a
GridView
).正如前面的评论者之一提到的,RowDataBound 事件不会为页脚触发。 我发现另一个代码片段解决了这个问题,但除了显示页脚,它显式创建行(触发 RowCreated 事件)并绑定它(触发 RowDataBound 事件)。
我已使用代码转换器将上面引用的代码转换为 C#,并进行了一些细微的调整。 我还添加了我在逐步分解代码时所做的评论。 RowCreated 和 RowDataBound 事件现在正在触发,我可以填充页脚中的下拉列表。
As one of the previous commenters mentioned, the RowDataBound event doesn't fire for the footer. I found another code snippet that addresses this issue, but in addition to displaying the footer, it explicitly creates the row (firing the RowCreated event) and binds it (firing the RowDataBound event).
I've converted the above referenced code to c# using a code converter and made a few minor tweaks. I also included the comments I made as I stepped through the code to break it down. The RowCreated and RowDataBound events are firing now and I'm able to populate dropdowns in footers.