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:
2- You make a ItemCommand event and define condition on it
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 evalVisible='<%# 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
Post a Comment