要实现的效果:
用GridView生成了一个数据列表,现在想在没有数据的时候,GridView隐藏。同时GridView的位置出现信息提示:“暂时还没有这类的信息”。请问这样的效果,是不是要:判断数据源是否为空,如果为空“GridView”隐藏,同时含有“提示信息的面板”显示。否则,“提示信息的面板”隐藏,“GridView”显示请问,还有没有其它的实现方式???

解决方案 »

  1.   

    <EmptyDataTemplate>
    <td nowrap align="center">标题</td>
    <TD noWrap align="center">类型</TD>
    <td nowrap align="center">操作</td>
    </EmptyDataTemplate>
    <EmptyDataRowStyle CssClass="gridheader" />  EmptyDataText="暂没有数据"
      EmptyDataRowStyle-HorizontalAlign="center"
      EmptyDataRowStyle-Font-Bold="true"
    <%
    if(ds==null)
    {}
    %>
      

  2.   


    <script language="C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            gridview1.DataSource = null;
            gridview1.DataBind();
        }    protected void btnSet_Click(object sender, EventArgs e)
        {
            gridview1.DataSource = new string[] { "123" };
            gridview1.DataBind();
        }
    </script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="gridview1" runat="server">
                <EmptyDataTemplate>
                    no data...
                </EmptyDataTemplate>
            </asp:GridView>
        </div>
        <asp:Button ID="btnSet" runat="server" Text="测试" OnClick="btnSet_Click" />
        </form>
    </body>
    </html>
      

  3.   

    LZ  用两个层div  就可以解决问题    div1放 gridview
       div2放  提示的话
       
        gridview绑定的时候数据源为空 自然页面就什么也没有
        
      

  4.   

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataTable dt = new DataTable();
                    if (dt.Rows.Count == 0)
                    { 
                        this.GridView1.EmptyDataText = "暂时没有数据";
                        this.GridView1.DataBind();
                    }
                    else
                    {
                        this.GridView1.DataSource = dt;
                        this.GridView1.DataBind();
                    }
                }
            }
      

  5.   


    再次请问各位大侠,Repeater里可以使用吗?
      

  6.   

    <EmptyDataTemplate>
            抱歉,暂时没有数据信息!
            </EmptyDataTemplate>
    在Repeater里可以使用吗???
      

  7.   

    repeart应该没有 ,得在后台写
      

  8.   

    在前台放个label,后台判断如果数据源为空,就显示label。label中设置你要显示为空的内容
      

  9.   

    gridView 外层加个div  . runat="server" .
    当然gv没有值时侯 gv.InnerHtml ="提示消息 " .
    可否 ?
      

  10.   

    if(dt.Rows.Count > 0)
    {
       DataGrid.DataSource = dt;
       DataGrid.DataBind();
    }
    else
    {
       lbl.Text = "暂时没有数据";
       DataGrid.DataSource = dt;
       DataGrid.DataBind();
    }
      

  11.   


    <!--GridView有个空模板列,当数据源为空显示-->
    <EmptyDataTemplate>
            <table>
                <tr>
                    <td>ZZZ</td>
                </tr>
            </table>
        </EmptyDataTemplate>
    <!--Repeater可以在FooterTemplate里判断-->
    <FooterTemplate>
            <%if (Repeater1.Items.Count == 0)
              { %>
              <table>
                <tr><td>空</td></tr>
              </table>
            <%} %>
            </FooterTemplate>
      

  12.   

    只需将gridview中emptydatatext的属性填写上“暂时还没有这类的信息”即可