Solved

Detailview - hide row if empty

Posted on 2011-02-13
8
837 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net web application 3 58
How to filter by key press ? 6 65
Securing WEBAPI on Azure 2 54
Shared Service Environment 2 54
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

737 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