Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

hide div/panel when datatable is empty

Posted on 2011-09-09
5
438 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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