EmptyDataTemplate and EmptyDataText not working in GridView

余生颓废 提交于 2019-12-01 18:08:45

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.

TreK

I ran into a similar problem and noticed I had logic around my DataBind to ignore the databinding method if my datasource was empty.

The EmptyDataTemplate will override any EmptyDataText, so it could be that you've defined the template incorrectly somehow, which is keeping you from seeing the EmptyDataText.

If you're binding an empty list to the GridView, it should display the EmptyDataText, so long as you don't have a conflicting EmptyDataTemplate, e.g.

<%-- GridTest.ascx --%>
<asp:GridView ID="Grid" runat="server" EmptyDataText="No Data!" />

// GridTest.ascx.cs
Grid.DataSource = new List<object>();
Grid.DataBind();

Are you doing something different than this?

Can User Empty Data Template.....

    <Columns>
             ............
             ............
             ............
    <Columns>
<EmptyDataTemplate>
        <asp:Label ID="lblEmptyTxt" runat="server" Text="No Data"></asp:Label>
      </EmptyDataTemplate>
                        </asp:GridView>

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!