Q:

How to add textbox or label in aspx repeater control by using if statement?

i would like to add textbox or label by using if statement. My coming data "-" or any price value. if data is equal to "-" (which means empty...), use label. OR if data is equal to "45 or 56 or etc" (which means price), use textbox. But error return to me while running below codes.
Error: "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. – " in if Eval blog....
         <td align="left">

                                <%  if (Eval("SERVICE_AMOUNT").ToString() != "-")
                                    { %>
                                 <asp:TextBox ID="priceTextBox" runat="server" Text='<%# FieldFormat(Eval("SERVICE_AMOUNT")) %>' AutoPostBack="true"></asp:TextBox>
                                 <%}
                                    else
                                    { %>
                                    <asp:Label runat="server" ID="lblServiceAmount" Text='<%# FieldFormat(Eval("SERVICE_AMOUNT")) %>'></asp:Label>
                                    <%} %>
                                </td>

A:

I suggest you to place both controls in .aspx and then implement your hiding logic in code-behind in ItemDataBound event.
An example:
protected void RepeaterItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
        string serviceAmount = DataBinder.Eval(e.Item.DataItem, "SERVICE_AMOUNT").ToString();

        var priceTextBox = e.Item.FindControl("priceTextBox") as TextBox;
        var lblServiceAmount = e.Item.FindControl("lblServiceAmount") as Label;

        priceTextBox.Visible = serviceAmount != "-";
        lblServiceAmount.Visible = !priceTextBox.Visible;

    }
}

