VBdotnet2005
asked on
Detailview - hide row if empty
How can I not display my detailsView row if value is empty?
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
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
ASKER
account 12345
address
city
address
city
ASKER
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
account 12345
address
Home phone 949 394-2222
job IT
order 5
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
ASKER
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
account 12345
address <<<<<<<<<<<< does not hide
Home phone 949 394-2222
job IT
order 5
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
adding Trim does it. thank you very much
ASKER
Protected Sub DetailsView1_DataBound(ByV
Dim row As DetailsViewRow
For Each row In DetailsView1.Rows
If String.IsNullOrEmpty(row.C
row.Visible = False
End If
Next
End Sub