每当查询无数据的时候,下面光秃秃的,很难看。我想让他在无数据的时候也显示标题行,该怎么设置?

解决方案 »

  1.   

    设置AutoGenerateColumns="false"
    然后手动设置需要的列,并且设置EmptyTemplate中的显示提示即可。http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx
      

  2.   

    方法一:后台可以 this.GridView1.EmptyDataText = "没有任何数据";方法二:前台可以加个空模板

    <EmptyDataTemplate>
        没有任何数据
    </EmptyDataTemplate>

      

  3.   

    select * from table where  1 = 2
      

  4.   

    完全可以显示标题啊,需要显示什么标题自己加
    <EmptyDataTemplate>
             <asp:Table ID="Table2" runat="server" Width="560px" BorderWidth="1px"
                    BorderStyle="Solid" CaptionAlign="Top">
                    <asp:TableRow runat="server" BorderStyle="Solid" BorderWidth="1px"
                        Height="20px" VerticalAlign="Top">
                        <asp:TableCell runat="server" BorderStyle="Solid" BorderWidth="1px">Picture</asp:TableCell>
                        <asp:TableCell runat="server" BorderStyle="Solid" BorderWidth="1px">Introduction</asp:TableCell>
                        <asp:TableCell runat="server" BorderStyle="Solid" BorderWidth="1px">Room</asp:TableCell>
                        <asp:TableCell runat="server" BorderStyle="Solid" BorderWidth="1px">Price</asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow runat="server" Height="20px" HorizontalAlign="Center">
                        <asp:TableCell runat="server" BorderStyle="Solid" BorderWidth="1px"
                            ColumnSpan="4" ForeColor="Red">No data is found! Please change search
                        options and try again.</asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow runat="server" Height="444px">
                    </asp:TableRow>
                </asp:Table>
    </EmptyDataTemplate>