EmptyDataTemplate 和 EmptyDataText 在 GridView 中不起作用
我似乎无法让 GridView
的 EmptyDataTemplate
或 EmptyDataText
工作。
我正在代码隐藏中获取 GridView 内容并使用 DataBind() 附加它们。我尝试将它们设置为 null
和空的 List
,在这两种情况下,我都将文本放入 EmptyDataTemplate
或 EmptyDataText不显示
。
我做错了什么?
编辑(代码片段)
这是我的GridView:
<asp:GridView ID="grid" runat="server" EmptyDataText="EMPTY">
</asp:GridView>
我已经尝试过这两个来绑定数据:
grid.DataSource = new List<object>();
grid.DataBind();
grid.DataSource = null;
grid.DataBind();
I can't seem to get either EmptyDataTemplate
or EmptyDataText
of a GridView
to work.
I'm fetching the GridView
contents in de codebehind and attaching them with using DataBind()
. I've tried having them as null
and as an empty List
, and in both cases the text I put into EmptyDataTemplate
or EmptyDataText
is not displayed.
What am I doing wrong?
EDIT (Code snippet)
This is my GridView:
<asp:GridView ID="grid" runat="server" EmptyDataText="EMPTY">
</asp:GridView>
And I've tried these two for binding the data:
grid.DataSource = new List<object>();
grid.DataBind();
grid.DataSource = null;
grid.DataBind();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此问题是由使用所谓的 CSS 友好控制适配器 引起的。启用它们后(它们似乎默认启用),
EmptyDataTemplate
和EmptyDataText
无法按预期工作。要禁用适配器,请转到
App_Browsers
文件夹,然后在CSSFriendlyAdapters.browser
文件中注释掉以下部分(或与您正在使用的控件相关的部分) ):最大的问题是样式会消失。
This problem is caused by using the so-called CSS-Friendly Control Adapters. With them enabled (and they seem to be enabled by default),
EmptyDataTemplate
andEmptyDataText
don't work as expected.To disable the adapters, go to the
App_Browsers
folder, and in theCSSFriendlyAdapters.browser
file, comment out the following section (or the section related to the control you're using):The big problem is the styles will go away.
我遇到了类似的问题,并注意到如果我的数据源为空,我的 DataBind 周围有逻辑忽略数据绑定方法。
I ran into a similar problem and noticed I had logic around my DataBind to ignore the databinding method if my datasource was empty.
EmptyDataTemplate
将覆盖任何EmptyDataText
,因此您可能以某种方式错误地定义了模板,这导致您看不到EmptyDataText
。如果您将空列表绑定到 GridView,它应该显示
EmptyDataText
,只要您没有冲突的EmptyDataTemplate
,例如您是否在做不同的事情比这个?
The
EmptyDataTemplate
will override anyEmptyDataText
, so it could be that you've defined the template incorrectly somehow, which is keeping you from seeing theEmptyDataText
.If you're binding an empty list to the GridView, it should display the
EmptyDataText
, so long as you don't have a conflictingEmptyDataTemplate
, e.g.Are you doing something different than this?
用户可以使用空数据模板吗......
Can User Empty Data Template.....
不要做我所做的事情 - GridView ForeColor 属性未设置,它默认为白色,这也是我的 BackColor 属性!
And don't do what I did - The GridView ForeColor property wasn't set and it defaults to white which was also my BackColor property!