Question

I'm trying to validate a page on our ASP.Net site that the developers used a gridview on. It seems that initially they are using a "placeholder" gridview that is getting hidden or visible based on some buttons being clicked to show data. Before these button clicks however, I'm seeing an empty table and the validation tool I'm using is complaining about no tbody or tr tags. Is there a way to completely hide the table tag or alternately to insert a tbody/tr within the hidden gridview?

Here is the gridview tag in the aspx.vb file:

<asp:GridView ID="GridView1"  runat="server" AutoGenerateColumns="False" summery="This table displays system notification items."
 AllowPaging="True" PagerSettings-Position="Top" PagerStyle-HorizontalAlign ="Right" PageSize ="15"  >
<Columns>
    <asp:TemplateField>
     <ItemTemplate>
      <asp:Image ID="image1" runat="server" ImageUrl="~/cmsicons/flag_red.gif" AlternateText="Overdue" Visible='<%# Eval("IsVisible")%>'/>
     </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataFormatString="{0:MM/dd/yyyy}" DataField="showdate" HeaderText="Due Date" 
        SortExpression="showdate"  />
        <asp:BoundField DataFormatString="{0:MM/dd/yyyy}" DataField="ModifiedDate" HeaderText="ModifiedDate" 
        SortExpression="ModifiedDate"  />
    <asp:TemplateField HeaderText="Data ID" SortExpression="DataRecordID">            
        <ItemTemplate>   
          <asp:HyperLink text='<%# Eval("DataRecordID") %>'  runat="server" NavigateUrl='<%# Eval("DataRecordID", "CMSManageAllDataRecord.aspx?dataid={0}") %>' ></asp:HyperLink> 
        </ItemTemplate> 

        </asp:TemplateField> 

    <asp:BoundField DataField="RecordName" HeaderText="Title" 
        SortExpression="RecordName" />       
    <asp:BoundField DataField="subcdrl" HeaderText="CDRL Number" 
        SortExpression="subcdrl" />        
    <asp:BoundField DataField="subcdrl" HeaderText="Sub Cdrl Count" 
        SortExpression="subcdrl" Visible ="false"  /> 
    <asp:BoundField DataField="StatusName" HeaderText="Status" 
        SortExpression="StatusName" />

</Columns>
<EmptyDataTemplate>
                <div>No Data found</div>
            </EmptyDataTemplate>
 <FooterStyle CssClass="GridViewFooterStyle" />
<RowStyle CssClass="GridViewRowStyle" />    
<SelectedRowStyle CssClass="GridViewSelectedRowStyle" />
<AlternatingRowStyle CssClass ="GridViewAlternatingRowStyle" />
<PagerStyle CssClass="GridViewPagerStyle" HorizontalAlign="Right"    />
<HeaderStyle CssClass="GridViewHeaderStyle" />

</asp:GridView>

And here is the output I see when I view source:

<div class="AspNet-GridView" id="ctl00_ContentPlaceHolder1_GridView1">
          <table cellpadding="0" cellspacing="0" summary="">
          </table>

</div>
Was it helpful?

Solution

You can definitely hide it with Javascript, if that's an option, one way would be

<script>
function hideGV(){
    document.getElementById('<%=GridView1.ClientID%>').style.display='none';
}
</script>

If rather want to insert the tbody/tr elements and using jQuery is an option for you, here's an example.

jQuery option to insert tbody/tr

<script>
​$(function(){
    $('#<%=GridView1.ClientID%>').append('<tbody><tr><td></td></tr></tbody>');
});​
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top