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

Solved: 

When we use conditions on Eval many times we got the error, two ways use solve this error.

1- You make a function what you needs and bind before eval

Example:

bool ShowAge(int age)
{
     return (age > 18);
}
and call where you use eval

Visible='<%# ShowAge(Eval("Age")) %>'

2- You make a ItemCommand event and define condition on it

protected void rptUser_ItemDataBound(object source, RepeaterCommandEventArgs e)
{    
     TextBox txtAge = (TextBox)e.Item.FindControl("txtAge");     
     if (DataBinder.Eval(e.Item.DataItem, "Age") > 18)
     {
          txtAge.Visible = false;
     }
;}











Comments

Popular posts from this blog

Add Image through base64 on PDF in itextsharp

how to insert text and tags at the cursor CKEDITOR