Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a table that i am generating using the ASP Table control and i am using a combination of CSS and javascript to make the table rows clickable. I use the CSS Code below to highlight the entire row and change the mouse to a pointer so it appears as a link:
CSS
table tr:hover{
    background:#00ff90;
    cursor:pointer;
}


I use the Javascript below to highlight the row that was selected.
JavaScript
function highlight(id) {
    document.getElementById(id).className = "highlightthis";
}


If i code the html by hand for the table, it looks like this and it works.
HTML
<table>
    <tr id="row1" onclick="highlight('row1')">
        <td>col 1</td>
        <td>col 2</td>
        <td>col 3</td>
        <td>col 4</td>
    </tr>
    <tr id="row2" onclick="highlight('row2')"&>
        <td>col 1</td>
        <td>col 2</td>
        <td>col 3</td>
        <td>col 4</td>
    </tr>
</table>


However, i am not codding the html by hand, i am using the asp table control and VB code to generate each row and each cell in the table. my VB Code looks like this.

VB
Private Sub DisplayAmortization()
    tblamortization.Rows.Clear()
    Dim row As New TableRow
    Dim cell As New TableCell
    Dim rc As String
    For Each dr As DataRow In dtamortization.Rows
        row = New TableRow
        For i As Integer = 0 To dtamortization.Columns.Count - 1
            cell = New TableCell
            cell.Text = CType(dr(i), String)
            cell.CssClass = "Column" & (i + 1).ToString
            row.Cells.Add(cell)
        Next
        rc = "row" & CType(dr(0), String)
        row.Attributes("Id") = rc
'Here lies the issue i am having
        row.Attributes("onclick") = "highlight('" & rc & "')"
        tblamortization.Rows.Add(row)

    Next
    tblamortization.Visible = True
    tblamortization.CssClass = "Amortizationtable"
End Sub


in order to add the Id and onclick arrtibutes to the tr element, i am using the tablerow.attribute method. When this generates, it should generate code similar to
HTML
<tr id="row1" onclick="highlight('row1')">
, but when i run the code in a browser, and click on view source, asp replaces the single quotes with the html quote for a single quote " & # 39" as a result, by call to the javascript does not fire correctly. how can i get asp to dispaly the single quote instead of the code for a single quote?
Posted
Updated 6-Jun-15 3:01am
v3
Comments
Sergey Alexandrovich Kryukov 5-Jun-15 23:30pm    
There is no such thing as "Java Script". Java is not a scripting language. ;-)
And the code you show resembles VB.NET a bit. What does it mean? No JavaScript code anywhere. If you think that many members like riddles, I'm afraid to disappoint you.
—SA
Dino the Sink 6-Jun-15 8:28am    
Actually, there is such thing as javascript, it is a client side scripting language and it actually is what a log of asp.net is built on behind the scenes. and as i said, the javascript runs correctly, so i did not feel it was necessary to include that in the post. And rather than being an A-hole with your riddle comment, a simple "This is a little confusing" would have been more appropiate. i will edit my original post and maybe someone with more manners could comment.
Sergey Alexandrovich Kryukov 6-Jun-15 12:40pm    
Did you really read my comment? I did not say "There is no such thing as "javascript", I said "There is no such thing as "Java Script". Can you spot the difference? Do you know there is also Java which has nothing do to with JavaScript?

I did not say anything rude for you, but you jumped straight to rude words which is completely unacceptable in this community. By saying such words, you loose your moral rules to tell others how to express ourselves. For this little offense, you already deserve kicking off your membership. I said what I meant to say, the fact that did not address your person at all. There was nothing "little confusing"; don't try to put your own words in others mouth. No discussions anymore.

—SA
Kornfeld Eliyahu Peter 7-Jun-15 5:43am    
Try
row.Attributes.Add("onclick", "highlight('" & rc & "')")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900