[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-02-16
3
Medium Priority
?
567 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:crundle
  • 3
3 Comments
 
LVL 16

Assisted Solution

by:sunithnair
sunithnair earned 2000 total points
ID: 23651998
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
 
LVL 16

Expert Comment

by:sunithnair
ID: 23652037
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
 
LVL 16

Accepted Solution

by:
sunithnair earned 2000 total points
ID: 23652057
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question