Solved

hide div/panel when datatable is empty

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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