0

我有以下gridview。没有错误,但是当我使用 w3c 验证器验证页面并且不存在任何行时,colspan 属性会获取 gridview 中已定义列的数量的值。当没有行时,我们有没有机会让 gridview 删除 colspan 属性?

 <asp:GridView ID="gv1" AutoGenerateColumns="False" ShowFooter="true" runat="server"
        AllowSorting="true" AllowPaging="true" CssClass="gridview" OnDataBound="gv_DataBound"
        OnRowDataBound="gv_RowDataBound" DataKeyNames="id" CellSpacing="-1" GridLines="None"
        EmptyDataText="no reference substances linked!">
        <Columns>
            <asp:HyperLinkField DataTextField="name" HeaderText="reference substance" DataNavigateUrlFormatString="~/ReferenceSubstances/{0}.aspx"
                DataTextFormatString="{0}" Target="_self" DataNavigateUrlFields="id" SortExpression="name" />
            <asp:BoundField DataField="supplier" HeaderText="supplier" SortExpression="supplier" />
            <asp:BoundField DataField="supplier_code" HeaderText="supplier code" SortExpression="supplier_code" />
            <asp:BoundField DataField="lot" HeaderText="lot" SortExpression="lot" />
        </Columns>
        <PagerStyle CssClass="footer" />
        <PagerTemplate>
            <asp:GridViewPager ID="GridViewPager1" runat="server" />
        </PagerTemplate>
    </asp:GridView>
4

3 回答 3

0

尝试这个

 <asp:GridView ID="gv1" AutoGenerateColumns="False" ShowFooter="true" runat="server"
        AllowSorting="true" AllowPaging="true" CssClass="gridview" OnDataBound="gv_DataBound"
        OnRowDataBound="gv_RowDataBound" DataKeyNames="id" CellSpacing="-1" GridLines="None"
>
     <EmptyDataTemplate>
                                    no reference substances linked!
                                </EmptyDataTemplate>
        <Columns>
            <asp:HyperLinkField DataTextField="name" HeaderText="reference substance" DataNavigateUrlFormatString="~/ReferenceSubstances/{0}.aspx"
                DataTextFormatString="{0}" Target="_self" DataNavigateUrlFields="id" SortExpression="name" />
            <asp:BoundField DataField="supplier" HeaderText="supplier" SortExpression="supplier" />
            <asp:BoundField DataField="supplier_code" HeaderText="supplier code" SortExpression="supplier_code" />
            <asp:BoundField DataField="lot" HeaderText="lot" SortExpression="lot" />
        </Columns>
        <PagerStyle CssClass="footer" />
        <PagerTemplate>
            <asp:GridViewPager ID="GridViewPager1" runat="server" />
        </PagerTemplate>
    </asp:GridView>
于 2013-08-05T12:50:40.617 回答
0

请添加 ShowHeaderWhenEmpty="true" 属性以在 gridview 没有记录时显示空数据文本。抱歉,如果这不是您要问的

<asp:GridView ID="gv1" ShowHeaderWhenEmpty="true" etc
于 2013-08-05T12:52:01.673 回答
0

听起来你需要一个EmptyDataTemplate

<asp:GridView ...
   <EmptyDataTemplate>
      render any markup
   </EmptyDataTemplate>
</asp:GridView>

替换render any markup任何与 w3c 兼容的标记。

于 2013-08-05T12:34:24.450 回答