ataTemplate和EmptyDataText在GridVi

ataTemplate和EmptyDataText在GridVi

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

问题描述

我似乎无法得到无论是 EmptyDataTemplate EmptyDataText GridView控件工作

我在取德codebehind的 GridView控件内容并使用它们连接的DataBind() 。我试着让他们为和一个空的列表,并在这两种情况下,我把到文本 EmptyDataTemplate EmptyDataText 不显示。

我在做什么错了?

修改(code段)

这是我的GridView的:

 < ASP:GridView控件ID =网格=服务器EmptyDataText =空>
< / ASP:GridView的>

和我已经试过这两种绑定的数据:

  grid.DataSource =新的List<对象>();
grid.DataBind();grid.DataSource = NULL;
grid.DataBind();


解决方案

这问题通过使用所谓的。有了它们启用(他们似乎默认启用), EmptyDataTemplate EmptyDataText 不正常工作。

要禁用适配器,转到 App_Browsers文件文件夹,并在 CSSFriendlyAdapters.browser 文件中注释掉以下部分(或与您所使用的控制部分):

 <适配器controlType =System.Web.UI.WebControls.GridView
               适配器类型=CSSFriendly.GridViewAdapter/>

最大的问题是样式会自行消失。

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();
解决方案

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.

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控件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 17:19