访问“第"在列表视图中 [英] Access "th" in Listview

查看:76
本文介绍了访问“第"在列表视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在后面的代码中是否有访问"th"的方法.我想根据项目值在页眉中添加填充.

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>

推荐答案

首先,为要更改的元素提供一个ID.在ListView的DataBind之后,您可以使用ListView的FindControl方法通过控件的ID访问该控件.然后,您可以将返回的控件转换为HtmlTableCell以正确处理它:

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;

这篇关于访问“第"在列表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆