简体   繁体   English

ASP.NET用户控件Eval()问题

[英]ASP.NET User control Eval() problem

I have a user control that contains a repeater. 我有一个包含转发器的用户控件。 I use the Eval() method to output data which works for the part of the repeater, but it doesn't output any data for the (Which uses the same code) 我使用Eval()方法输出适用于转发器部分的数据,但它不输出任何数据(使用相同的代码)

Any ideas why this isn't working? 任何想法为什么这不起作用?

I have the following code in the repeater user control: 我在转发器用户控件中有以下代码:

<asp:Repeater runat="server" ID="repeater1">
         <HeaderTemplate>
         //Data is not displayed in the HeaderTemplate
                <table class="datatable fullwidthpercent"> 
                <tr>
                   <th>
                        <%# Eval(Column2Name) %>
                   </th>
                </tr>
     </HeaderTemplate>
     <ItemTemplate>
     //Data is displayed in the ItemTemplate
            <tr>
                <td>
                    <%# Eval(Column2Name) %>
                </td>
            </tr>                   
            </ItemTemplate>

The Eval method needs a data item - there is no data item associated with a HeaderTemplate. Eval方法需要一个数据项 - 没有与HeaderTemplate关联的数据项。

From http://www.asp.net/data-access/tutorials/displaying-data-with-the-datalist-and-repeater-controls-vb : 来自http://www.asp.net/data-access/tutorials/displaying-data-with-the-datalist-and-repeater-controls-vb

When specifying the HeaderTemplate or FooterTemplate, the DataList adds an additional header or footer row to the rendered output. 指定HeaderTemplate或FooterTemplate时,DataList会向呈现的输出添加额外的页眉或页脚行。 Like with the GridView s header and footer rows, the header and footer in a DataList are not bound to data. 与GridView的页眉和页脚行一样,DataList中的页眉和页脚不会绑定到数据。 Therefore, any databinding syntax in the HeaderTemplate or FooterTemplate that attempts to access bound data will return a blank string. 因此,尝试访问绑定数据的HeaderTemplate或FooterTemplate中的任何数据绑定语法都将返回空字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM