Hi. I am creating an asp.net web site. Using GridView the website creates a table. Now my question is I want to write a javascript function that colors the text "NO" red within the table cells. Waiting for your reply.

Why do you need Javascript if all you want to do is color the text? You can very well use CSS to do the same.

<html>
<head>
    <title>Example</title>
</head>
<body>
    <table style="border: 1px solid green; color: red">    
        <tr>    
            <td>Hello to all</td>
            <td>This is some dummy text</td>
        </tr>
    </table>
</body>
</html>

Hi. I only want to color the cells containing the word "NO" not the other ones.... can this too be done with CSS?? Thanks in advance

Seeing that you are using ASP, you can use the ASP constructs to do selective rendering.

<html>
<head>
    <style>
        .wrong
        {
            color: red;
        }
        .right
        {
            color: green;
        }
    </style>
    <title>Example</title>
</head>
<body>
    <table style="border: 1px solid green;">
    <tr>
    <%
        dim i
        for i = 1 to 6
           if text = 'NO' then
                response.write("<td class='wrong'>" & text & "</td>")
           else
                response.write("<td class='right'>" & text & "</td>")
           end if
        next
    %>
    </tr>
    </table>
</body>
</html>

Though I am not sure on the ASP code I have written, this is pretty much what you would have to do. This will be either Javascript code or ASP code depending on where the data is coming form i.e. client side or server side.

Hi.Thank you for your prompt response. However there is still a problem. My table being dynamic not only grows in columns but in rows also. Is there no way to reach the elements within the cell and do a

if(document.cell=="NO") {
color.cell(red);
}

Or is there a way to reach the cell from GridView (I am using ASP.Net) Any help would be welcome. Thanks again and waiting for your reply...

It would be really better if you post the same question with the CSS solution I have provided to you to the ASP.NET section since this has ceased to be a CSS problem and is more of ASP thing.

Once you get what you are looking for, using the class attributes and applying the style of your choice is pretty easy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.