tags:

views:

57

answers:

1

I trying to execute the follow code in .aspx page:

<asp:Repeater ID="rptComentarios" runat="server">
            <ItemTemplate>
                <% if (Convert.ToInt32(Eval("int_tipo")) == 1)
                   { %>
                                        <div class="resp">
            <div class="top">
            </div>
            <div class="cont-resp">
                <h3>
                    <%# Eval("txt_nome") %></h3>
                <p>
                 <%# Eval("txt_comentario") %></p>
            </div>
        </div>
                   <% }
                   else
                   {%>
                               <div class="usuario">
            <div class="top">
            </div>
            <div class="cont-usuario">
                <h3>
                       <%# Eval("txt_nome") %></h3>
                <p>
                    <%# Eval("txt_comentario") %></p>
            </div>
        </div>
                   <% } %>
            </ItemTemplate>
            </asp:Repeater>

It throws an exception in runtime in first line:

  <% if (Convert.ToInt32(Eval("int_tipo")) == 1)

System.InvalidOperationException: Databinding methods such as Eval(), XPath() och Bind() can only be used in the context of a databound control.

Whats wrong?Any ideias?

+2  A: 

I think there needs to be a # sign for the enclosure <%# ..Eval...%>

Or try the full Eval version

<%# if (Convert.ToInt32(DataBinder.Eval(Container.DataItem, "int_tipo"))
                                                                    == 1) { %>
Glennular
yes i do think so,but i cant insert "#" in this line
its wrong cannot use "#" within if/else clauses