EmptyDataTemplate 和 EmptyDataText 在 GridView 中不起作用 [英] EmptyDataTemplate and EmptyDataText not working in GridView

查看:18
本文介绍了EmptyDataTemplate 和 EmptyDataText 在 GridView 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆