我有以下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>
答案 0 :(得分:0)
听起来你需要一个EmptyDataTemplate
:
<asp:GridView ...
<EmptyDataTemplate>
render any markup
</EmptyDataTemplate>
</asp:GridView>
将render any markup
替换为任何兼容w3c的标记。
答案 1 :(得分: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>
答案 2 :(得分:0)
请添加ShowHeaderWhenEmpty =“true”属性以显示emptydatatext,而gridview没有记录。对不起,如果这不是你要求
<asp:GridView ID="gv1" ShowHeaderWhenEmpty="true" etc