Solved

hide div/panel when datatable is empty

Posted on 2011-09-09
5
442 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
[X]
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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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