Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

Using a table in ASP.NET

I have a table that (in a user control) that holds 2 columns and a bunch of rows. There is one row I need to populate when theres a value(not a problem) but when there is no value I want to collapse the <tr> and move on. There are controls in the tr like a label on one column and a text box holds the value and there is also a placeholder control. All I want to do is collapse(?) the row when there is no value. I see alot of javascript out there that does this but Im new to all this so Im not sure how to call the script or where to put the script(in the control or on the form that holds the user control?)
Can someone please help with this. I am trying to figure it out in the source code but I havent been able to do it just yet.
Im using ASP.NET 2012 .NET 4.0(VB source code)

Thanks
JK
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Maybe you can adapt this .

   Private Sub TestGridView_DataBindingComplete(ByVal sender As Object, _
    ByVal e As DataGridViewBindingCompleteEventArgs) _
    Handles DataGridView1.DataBindingComplete
 
        For Each Row As DataGridViewRow In CType(sender, DataGridView).Rows
            Dim Visible As Boolean = True
 
            'Do this to inspect all cells in the row
            For i As Integer = 0 To Row.Cells.Count - 1
                If Row.Cells(i).Value Is Nothing Then
                    Visible = False
                    Exit For
                End If
            Next
 
            'Or you can check specific columns for their values
            If Row.Cells(0).Value Is Nothing OrElse _
            (IsNumeric(Row.Cells(0).Value) AndAlso CInt(Row.Cells(0).Value) < 0) Then
                Visible = False
            End If
 
            Row.Visible = Visible
        Next
    End Sub

Open in new window

i would check in asp if there is data, if true,  then add row,  else dont add row.


or are you trying to do a fancy css where the thung collapses like an accordion
basically if you choose option 1, move the TR tag inside your asp code




so instead of

<tr><td>  <asp: value stuff> </td></tr>

you would do something like

 <asp..  if value exists  "<tr><td>" & valuestuff& "</td></tr>"   >


~~sorry for pseudocode,  im on cellphone
Avatar of jknj72
jknj72

ASKER

Randy, Im using a table not a gridview. Although, I though of converting the table into a grid but I dont have the time to do so. I simply want to keep the designated row at the original height and when populating the table with data, if there is no data for this row I would like to collapse it. I have another question as well. If there is a value I add a link to the <td> and I want to open up a new window with that is already in place. I just dont have the syntax down yet. Here is what I had given to me...
--first argument is an id and the second is supposed to be the screen resolution but I will figure that out. I just need to know if that is the right syntax to open up a new page? I will post a new question for this one...
"<a id="PcovIndivControl1_PcovAllNamesLink" class="PcovIndivLabelsBold"  onclick="OpenNewWindow('20140501060253390384276WBGZW2551       263','')" href="#">Additional Names on File. Click Here to view...</a>"
Maybe you can adapt this. They are hiding based on a value you will want to hide based on null, maybe.

The complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E2767.

The following example demonstrates how to hide particular rows and columns by handling the CustomFieldValueCells Event.

In this example, the event handler iterates through all row headers and removes rows that correspond to the "Employee B" field value, and that are not Total Rows.
Avatar of jknj72

ASKER

Randy, I appreciate your help but once again, I am not using a grid....I am using an html table and I dont have these properties with the table ...
to open a new window use the tag  _default
ASKER CERTIFIED SOLUTION
Avatar of Ess Kay
Ess Kay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you don't want row to show,  and using table,  use code i have above
try this code on for size,  its how to create html table in asp dynamically http://www.dotnetcurry.com/ShowArticle.aspx?ID=135
Avatar of jknj72

ASKER

thanks