0

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>
Levi Wallach
  • 369
  • 5
  • 17

1 Answers1

1

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>
Icarus
  • 63,293
  • 14
  • 100
  • 115
  • So, I tried adding the code in the Master Page that this one is contained in but it tells me that GridView1 isn't defined. Any hints as to how to get around that? – Levi Wallach Dec 12 '12 at 20:00
  • You need to add the code to the page where the GridView is defined. The Master Page won't have a reference to the GridView and thus throw the error you see. – Icarus Dec 12 '12 at 20:21
  • I'm sorry to bug you with this but I get intellisense errors when I try to insert a script tag in the called page. Tried within the content tag and outside of it. I know there's some way of doing this but I can't seem to find it - sorry, I'm not very experienced with ASP.Net. :( – Levi Wallach Dec 12 '12 at 20:27
  • @LeviWallach you just need to put everything inside a script tag. I will edit my answer. – Icarus Dec 12 '12 at 20:54
  • Sorry for the delay. I had these in script tags already but it looked like intellisense was complaining but it wasn't really. When I use the second block of code you provide, and look at the source, it does substitute the propper id for the div around the gridview, but it doesn't seem to append the code. There is already a table tag in there so I'd assume you'd want to append it onto that, but before I even get there it's not doing any appending regardless. So will have to troubleshoot why this isn't working a bit more, thanks for the suggestion. – Levi Wallach Dec 19 '12 at 16:16