?
Solved

hide div/panel when datatable is empty

Posted on 2011-09-09
5
Medium Priority
?
471 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
ID: 36509925
If tbMaterialVersion.Rows.Count = 0 Then


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

Author Comment

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

Expert Comment

by:russellC
ID: 36510051
woops sorry itsearly still
0
 

Author Comment

by:swgdesign
ID: 36510671
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 1000 total points
ID: 36512767
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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