Fallenreaper Fallenreaper - 1 month ago 10
ASP.NET (C#) Question

How do you determine if a HtmlTableCell control is a th or td?

I was iterating through a table I had created and getting the first cell from each row. Based on what type the cell was, would do different things. Example:

if(cCell.type=='th' && cCell.parent.next.Cells[0].type == 'th'){
cCell.parent.parent.controls.remove(cCell.parent);
}


stating, if both the current cell and the cell below it are th, then to delete current cells row.

Answer

Tom Ingram seems to be correct...

    foreach (HtmlTableRow row in MyTable.Rows)
    {
        if (row.Cells[0].TagName.ToLower() == "th")
        {
            // header.
        }
        else
        {
            // cell.
        }
    }

example table used...

<table runat="server" id="MyTable">
    <tr>
        <th>header 1</th>
        <th>header 2</th>
    </tr>
    <tr>
        <td>cell 1</td>
        <td>cell 2</td>
    </tr>
</table>
Comments