Theomax
Theomax

Reputation: 6810

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>

Upvotes: 0

Views: 1128

Answers (1)

Luke Girvin
Luke Girvin

Reputation: 13452

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.

Upvotes: 2

Related Questions