开发者

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)

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.

From 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. Like with the GridView s header and footer rows, the header and footer in a DataList are not bound to data. Therefore, any databinding syntax in the HeaderTemplate or FooterTemplate that attempts to access bound data will return a blank string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜