简体   繁体   中英

Binder to string

how to put <%# DataBinder.Eval(Container, "DataItem.Code") %> to string in aspx file? like <% string str = DataBinder.Eval(Container, "DataItem.Code") %> ? I am getting error The name 'Container' does not exist in the current context

You could write a helper function in your code behind which will return the required string:

protected string MyFunction(object item)
{
    ... do some calculations and return a string
}

and then in your view whenever you needed the value you could call this function:

<%# MyFunction(DataBinder.Eval(Container, "DataItem.Code")) %>

This way you no longer need a variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM