EmptyDataTemplate 和 EmptyDataText 在 GridView 中不起作用

编程入门 行业动态 更新时间:2024-10-25 02:21:19
本文介绍了EmptyDataTemplate 和 EmptyDataText 在 GridView 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我似乎无法让 GridViewEmptyDataTemplateEmptyDataText 工作.

I can't seem to get either EmptyDataTemplate or EmptyDataText of a GridView to work.

我正在获取代码隐藏中的 GridView 内容并使用 DataBind() 附加它们.我试过将它们作为 null 和空的 List,在这两种情况下,我都将文本放入 EmptyDataTemplateEmptyDataText 不显示.

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.

我做错了什么?

编辑(代码片段)

这是我的 GridView:

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();

推荐答案

这个问题是使用了所谓的CSS 友好的控制适配器.启用它们后(它们似乎默认启用),EmptyDataTemplateEmptyDataText 无法按预期工作.

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 and EmptyDataText don't work as expected.

要禁用适配器,请转到 App_Browsers 文件夹,然后在 CSSFriendlyAdapters.browser 文件中,注释掉以下部分(或与您的控件相关的部分)'正在使用):

To disable the adapters, go to the App_Browsers folder, and in the CSSFriendlyAdapters.browser file, comment out the following section (or the section related to the control you're using):

<adapter controlType="System.Web.UI.WebControls.GridView"
               adapterType="CSSFriendly.GridViewAdapter" />

最大的问题是样式会消失.

The big problem is the styles will go away.

这篇关于EmptyDataTemplate 和 EmptyDataText 在 GridView 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-01 10:09:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/828213.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   EmptyDataTemplate   EmptyDataText   GridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!