Need to add Gridview to Table Cell or remove if Gridview is empty

Have a table with 3 rows for 3 different gridviews.  How do I get the gridviews in the table? When I put it inside <asp:TableCell></asp:TableCell>  it does not show the grideview on the screen but it will when rendered to a web browser. Also how can I have the row from the table removed when the grideview is empty?

200 points will be issued for getting the grideview in the table
300 points will be issues for getting the row from the table removed when gridvew is empty

<asp:TableRow runat="server" BackColor="White">
                                    <asp:TableCell>
                                    
                                        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" CellPadding="5" AllowSorting="True" GridLines="Horizontal" BorderStyle="None">
                                            <RowStyle BackColor="#ECE9D8" CssClass="BodyText"/>
                                             <Columns>
                                                 <asp:TemplateField HeaderText="CLID" SortExpression="CLID">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_CLick"  CommandArgument=<%#Eval("ShipmentID")%>> <%# Eval("CLID") %></asp:LinkButton>
                                                    </ItemTemplate>
                                                 </asp:TemplateField>                                        
                                             </Columns>
                                             <HeaderStyle CssClass="gvListHeaderRow" />
                                        </asp:GridView>
                                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dataSQLConnectionString %>" 
                                            SelectCommand="test2" SelectCommandType="StoredProcedure" >
                                            <SelectParameters>
                                                <asp:Parameter DefaultValue="46" Name="ClientID" Type="Int32" />
                                                <asp:Parameter DefaultValue="container" Name="ShipmentType" Type="String" />
                                                <asp:FormParameter Name="Search" DefaultValue="null" FormField="Searchbx" Type="String" />
                                                <asp:FormParameter Name="Active" DefaultValue="1" FormField="SearchActive" Type="String" />
                                            </SelectParameters>
                                        </asp:SqlDataSource>
                                    
                                    </asp:TableCell>
                                </asp:TableRow>

Open in new window

crundleAsked:
Who is Participating?
 
sunithnairConnect With a Mentor Commented:
You can do it in the DataBound event of the grid view like this
protected void GridView1_DataBound(object sender, EventArgs e)
{
  if(GridView1.Rows.Count == 0)
  {
     trGV1.Visible = false;
  }
}

Open in new window

0
 
sunithnairConnect With a Mentor Commented:
If you mean you want it to be shown in the VisualStudio then you can just use a normal table and give it as runat="server" like this
<tr id="trGV1" runat="server" style="background-color:White">
                                    <td>
                                    
                                        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" CellPadding="5" AllowSorting="True" GridLines="Horizontal" BorderStyle="None">
                                            <RowStyle BackColor="#ECE9D8" CssClass="BodyText"/>
                                             <Columns>
                                                 <asp:TemplateField HeaderText="CLID" SortExpression="CLID">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_CLick"  CommandArgument=<%#Eval("ShipmentID")%>> <%# Eval("CLID") %></asp:LinkButton>
                                                    </ItemTemplate>
                                                 </asp:TemplateField>                                        
                                             </Columns>
                                             <HeaderStyle CssClass="gvListHeaderRow" />
                                        </asp:GridView>
                                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dataSQLConnectionString %>" 
                                            SelectCommand="test2" SelectCommandType="StoredProcedure" >
                                            <SelectParameters>
                                                <asp:Parameter DefaultValue="46" Name="ClientID" Type="Int32" />
                                                <asp:Parameter DefaultValue="container" Name="ShipmentType" Type="String" />
                                                <asp:FormParameter Name="Search" DefaultValue="null" FormField="Searchbx" Type="String" />
                                                <asp:FormParameter Name="Active" DefaultValue="1" FormField="SearchActive" Type="String" />
                                            </SelectParameters>
                                        </asp:SqlDataSource>
                                    
                                    </td>
                                </tr>

Open in new window

0
 
sunithnairCommented:
And if you want to hide the row when the gridview is empty then you can go the following. Check if GridView1.Rows.Count == 0 and then hide trGV1 like this
if(GridView1.Rows.Count == 0)
{
   trGV1.Visible = false;
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.