?
Solved

Detailview - hide row if empty

Posted on 2011-02-13
8
Medium Priority
?
847 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 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