Solved

hide div/panel when datatable is empty

Posted on 2011-09-09
5
429 Views
Last Modified: 2012-06-21
I have a div that I want to hide when the rows.count of a dataset = 0 but my code does not work and the error is telling me the ID of the div is not defined...Any ideas?

I have also tried using a Panel but I get the same issue...
<div class="detailRow" id="ViewFilesDiv" runat="server">
                            <div class="leftcol">
                                <a href='javascript:ViewMaterialVersions(<%#DataBinder.Eval(Container.DataItem, "MaterialID")%>)'><img src="/images/viewfiles.png" /></a></div>
                            <div class="rightcol">&nbsp;
                            
                            </div>
                            <div class="floatfix"></div>
                        </div> 


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindDetails()
            Dim tbMaterialVersion As DataTable = New IMCSelect().getMaterialVersions(-1, DetailId, 1, 0, Application("logMaterials")).Tables(0)
            If tbMaterialVersion.Rows.Count = 0 Then
                ViewFilesDiv.visible = False
            End If
        End If
    End Sub

Open in new window

0
Comment
Question by:swgdesign
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:russellC
Comment Utility
If tbMaterialVersion.Rows.Count = 0 Then


Should be
If tbMaterialVersion.Rows.Count == 0 Then
0
 

Author Comment

by:swgdesign
Comment Utility
I am using VB.Net there is no == in vb only in C# and JS!
0
 
LVL 3

Expert Comment

by:russellC
Comment Utility
woops sorry itsearly still
0
 

Author Comment

by:swgdesign
Comment Utility
Here's the whole source in case I am being stupid and missing something;

The label is in a div within a repeater.


Partial Class ContentZone_PublicationSummary
    Inherits System.Web.UI.Page

    Public ReadOnly Property DetailId() As Integer

        Get
            If String.IsNullOrEmpty(Request.QueryString("Id")) Then
                Return 0
            Else
                Dim _DetailId As Integer = 0
                Integer.TryParse(Request.QueryString("Id"), _DetailId)
                Return _DetailId
            End If
        End Get

    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim tbPublicationPublication As DataTable = New IMCSelect().getPublications(DetailId, "", 1, 0, Application("logGeneric")).Tables(0)
            'If tbPublicationPublication.Rows(0)("").ToString <> "" Then
            '    lblDownloadFile.text = "sdsdsdd"
            'End If
            '<a href="/uploads/publications/<%#DataBinder.Eval(Container.DataItem, "PDFFile")%>">Download Summary</a>

            repDetails.DataSource = tbPublicationPublication
            repDetails.DataBind()
        End If
    End Sub


End Class


<div class="detailRow" id="divDownloadFile">
                        <div class="leftcol"></div>
                        <div class="rightcol">
                            <asp:Label ID="lblDownloadFile" runat="server" Text="Label"></asp:Label></div>
                        <div class="floatfix"></div>
                    </div>

Open in new window

0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 250 total points
Comment Utility
If the div is inside a Repeater then you will probably need to the the ItemDataBound event of the Repeater to turn off visibility if the data table is empty. Change the div to an asp:Panel so you can get a reference to it in the ItemDataBound event. Here's some sample code to get you started.
'Item Databound event handler

Protected Sub Repeater1_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim hiddenPnl As Panel = CType(e.Item.FindControl("divDownloadFile"), Panel)
            hiddenPnl.Visible = False
        End If
    End Sub


<!--ASPX markup-->

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
				<div><%# DataBinder.Eval(Container, "DataItem.MaterialId") %></div>						    
            
                <asp:Panel CssClass="detailRow" ID="divDownloadFile" runat="server">
                     <div class="leftcol"></div>
                     <div class="rightcol">
                            <asp:Label ID="lblDownloadFile" runat="server" Text="Label">Label</asp:Label>
                     </div>
                     <div class="floatfix"></div>
                </asp:Panel>
            </ItemTemplate>
        </asp:Repeater>

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now