Solved

Detailview - hide row if empty

Posted on 2011-02-13
8
836 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC -Add authentication 2 34
TimeZone, day light savings, Sql server, asp.net 6 38
IEnumerable<T> to a List<T> 8 51
asp web application 3 35
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…

679 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