I am trying to hide a TD named ImportnatInfo in a table when the gridview is empty. This gridview has one column from a table in a database to show. When this gridview is empty I want to hide the TD.
The following is the asp code:
<td runat ="server" ID="ImportnatInfo"
style="width: inherit; border: 5px double #585858; padding-left: 5px; padding-right: 5px;
height: inherit; background: #FFFFFF; background-position: center; border-radius: 25px;"
enableviewstate="True" visible="False">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderStyle="None"
DataSourceID="ImportantSqlDataSource">
<Columns>
<asp:BoundField DataField="Importatnat_Info" SortExpression="Importatnat_Info">
<ControlStyle BorderStyle="None" Height="10px" />
<FooterStyle BorderStyle="None" Height="10px" />
<HeaderStyle BorderStyle="None" Height="10px" />
<ItemStyle BorderStyle="None" Height="10px" HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ImportantSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AgainConnectionString %>"
SelectCommand="SELECT [Importatnat_Info] FROM [StationInfoTable] WHERE ([StationNo] = @StationNo)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlStationNames" Name="StationNo" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
</td>
And the VB.net code is the following:
If GridView1.Rows.Count = 0 Then
ImportnatInfo.Visible = False
Else
ImportnatInfo.Visible = True
End If
I have dropdownlist and i choose something everytime so if there is nothing in the grid to view, i want the whole TD to be invisible. the TD that im trying to hide when it is empty, the thing the TD is always visible because when there is nothing in the gridView Vb add so it won’t be empty. so i thought i should use the datasource and still not sure what to do. Any idea how to do that?
Yours is working good but you just need to add Else to show the TD after you check it is not