?
Solved

Detailview - hide row if empty

Posted on 2011-02-13
8
Medium Priority
?
840 Views
Last Modified: 2012-05-11
How can I not display my detailsView row if value is empty?
0
Comment
Question by:VBdotnet2005
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
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 2000 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

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 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