Avatar of M.L. Martin
M.L. MartinFlag for United States of America

asked on 

I want to elminate the space that is displayed between Multiple DetailViews if one is empty or NULL of values.

ASP.Net DetailsView question:
I have built an ASP.net page with Webforms and VB. I am passing a search parameter using a url value. On the results page I have multiple DetailView's. They are place one behind the other. Everything works fine but I want to eliminate the empty space when a data source connected to a DetailView is empty. Here is my example. The Header text says Behavior and Analysis:

Behavior and Analysis:
DetailView 1 - data source is not empty so display
DetailView 2 - data source is not empty so display
DetailView 3 - data source is empty
(Empty Spacing) After DetailView 3 there is empty space here (Empty Spacing)
DetailView 4 - data source is empty
(Empty Spacing) After DetailView 4 there is empty space here (Empty Spacing)
DetailView 5 - data source is not empty, display.

In my ASPx page there is space between the records displaying for DetailView 2 and DetailView 5 because even though no records are returned the DetailView Control still takes up space. How can I eliminate the empty space if the data source for DetailView 3 & 4 are empty? Basically, I want to eliminate the space between DetailViews id the data source is empty.
ASP.NETVB Script

Avatar of undefined
Last Comment
Chinmay Patel
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of M.L. Martin
M.L. Martin
Flag of United States of America image

ASKER

Thank you Chinmay. I was thinking along those lines but I was sure about the syntax. Below is what I have so far. I am sure it is not correct. If you can help me with the Syntax I will give that a try.

Protected Sub DetailsView1 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailesView1.Page_Load

       If DetailsView1.Items.Count = 0 Then
       DetailsView1.Visible = False
       End If

   
    End Sub
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

you are right. It will not work that way. As this is DetailsView, you should use

DetailsView.DataItemCount https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.detailsview.dataitemcount?view=netframework-4.7.2

i.e.      
If DetailsView1.DataItemCount = 0 Then
       DetailsView1.Visible = False
       End If

Open in new window

ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo