Solved

Detailview - hide row if empty

Posted on 2011-02-13
8
831 Views
Last Modified: 2012-05-11
How can I not display my detailsView row if value is empty?
0
Comment
Question by:VBdotnet2005
  • 5
  • 3
8 Comments
 

Author Comment

by:VBdotnet2005
ID: 34885400
I tried thise, and step though it, some found and row.Visible = False, but I don't see it hide them.

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound
        Dim row As DetailsViewRow
 
        For Each row In DetailsView1.Rows
            If String.IsNullOrEmpty(row.Cells(1).Text) Or row.Cells(1).Text = " " Then
                row.Visible = False

            End If
        Next
    End Sub
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 34885405
The answer is simply because there is no data to show.

To work around this used the emptydatatemplate element of dataview as discuss below:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.emptydatatemplate.aspx
0
 

Author Comment

by:VBdotnet2005
ID: 34885438
account          12345
address        
city
0
 

Author Comment

by:VBdotnet2005
ID: 34885448
I meant this. Hid Address if no value. I have not 100% underdstand you comment above.

account          12345
address        
Home phone   949 394-2222
job                   IT
order              5
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 34885481
Sorry, discard my previous comment, I misunderstood your question. Please try the below code instead. It will hide the rows of detailsview according to your needs.

:)
I tried thise, and step though it, some found and row.Visible = False, but I don't see it hide them.

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound
        Dim row As DetailsViewRow
 
        For Each row In DetailsView1.Rows
            If String.IsNullOrEmpty(row.Cells(1).Text) Or row.Cells(1).Text = " " Then
                row.Style.Add("display", "none")
            End If
        Next
    End Sub

Open in new window

0
 

Author Comment

by:VBdotnet2005
ID: 34885632
It still does not hide rows address if there is not value

account          12345
address                   <<<<<<<<<<<< does not hide
Home phone   949 394-2222
job                   IT
order              5
0
 
LVL 8

Accepted Solution

by:
PagodNaUtak earned 500 total points
ID: 34885642
Try the below code... Does row.Cells(1) refers to address? please check
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound  
        Dim row As DetailsViewRow  
   
        For Each row In DetailsView1.Rows  
            If String.IsNullOrEmpty(row.Cells(1).Text.Trim()) Or row.Cells(1).Text = "&nbsp;" Then  
                row.Style.Add("display", "none")  
            End If  
        Next  
    End Sub

Open in new window

0
 

Author Comment

by:VBdotnet2005
ID: 34885669
adding Trim does it. thank you very much
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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…

743 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

12 Experts available now in Live!

Get 1:1 Help Now