0

Is there a way to access the "th", in the code behind. I would like to add padding to the header depending on the item value.

<LayoutTemplate>
        <table runat="server" >
            <tr runat="server">
                <td runat="server">
                    <table ID="itemPlaceholderContainer" runat="server" border="0" class="UserLayoutTbl">
                        <tr runat="server" style="">
                            <th runat="server" width="140" align="left">
                                Date</th>
                            <th runat="server" width="140" align="left">
                                Ref. No.</th>
                            <th runat="server" width="270" align="left">
                                Description</th>
                           <%-- <th runat="server" width="90" align="right" style = '<%# GetAmountLabelStyle() %>'>
                                Amount</th>--%>
                                <th id="Th1" runat="server" width="90" align="right">
                                Amount</th>
                        </tr>
                        <tr ID="itemPlaceholder" runat="server">
                        </tr>
                    </table>
                </td>
            </tr>
Jerry Trac
  • 357
  • 4
  • 17

1 Answers1

1

First, give an ID to the element you want to change. After DataBind of the ListView, you can access the control by its ID using the FindControl method of the ListView. Then, you can convert the returned control to HtmlTableCell to proper handle it:

// thDate is the <th> ID
HtmlTableCell thDate = lstItems.FindControl("thDate") as HtmlTableCell;
Marcus Vinicius
  • 1,891
  • 1
  • 19
  • 35