How to select second td in detailsview datarow?
Asked Answered
W

2

34

I am trying create a new css for shaping my detailsview. But i couldn't reach to second td in detailsviews field rows. do you have any idea to access 2nd td?

But please imagine belov code generated by detailsview.

<table>
<thead>
...
</thead>

<tbody>
    <tr>
        <td>Name</td>
        <td><input type='text' id='txtName' /></td>
    </tr>
</tbody>
</table>

Widera answered 23/5, 2009 at 10:30 Comment(0)
M
77

The first question is: do you need to support IE6? If the answer is yes then you can't do it. If not the easiest solution is probably:

td + td { ... }

Even more modern (and less supported) is:

td:nth-child(2) { ... }

This presupposes that you're not willing or not able to put a class or other identifier on the second td so you can do it much more easily.

Mulch answered 23/5, 2009 at 10:38 Comment(1)
td+td selects 2nd, 3rd, 4th and so on.Tracheid
R
5

I'd recommend against selecting a field that happens to be the second in a row. A better approach would be to assign meaningful css classes to the fields and selecting those:

<head>
  <style type="text/css" media="screen">
    td.form-value {
      background-color:red;
    }
  </style>
</head>
<tr>
  <td class="form-label">
    Label:
  </td>
  <td class="form-value">
    ...
  </td>
</tr>
Resinous answered 23/5, 2009 at 10:47 Comment(1)
Can't add class name to second td.Widera

© 2022 - 2024 — McMap. All rights reserved.