One of the ASP's Net Data-bound controls can use a good Evil () syntax:
& lt; Div & gt; & Lt;% # Eval ("MyProp")% & gt; & Lt; / Div & gt;
But it is not possible to combine with conditional statements ?:
Good for that option
So - my choice is to keep part of the markup in codebahind. I really liked to keep it out there Any other possibilities?
& lt; Div runat = "server" view = '& lt;% #! String.IsNullOrEmpty (Eval ("MyProp") as a string)% & gt; '& Gt; & Lt;% # Eval ("MyProp")% & gt; & Lt; / Div & gt;
Edit 2010/9/30
Now I have a little time, I think I should The answer should be expanded. In particular, the idea is that the question is a duplicate which is already from my origin. So I will deal with the first part of your question:
Why can not you join? The reason is that code blocks are executed during the render step of the page life cycle. ASP.Net Your Code (in this case If the statement) puts it in a function, then that representative is sent as a representative, the problem is that your expression returns "MyProp" to the object. Page.GetDataItem is a bit of a magic call that calls only to call in the call stack. By the time the render phase comes, all the data binding has ended. So when you call Eval , which calls Page.GetDataItem in the implicit manner, the following error is thrown: "Database wont [... ] Can be used only in the context of one reference
then
code blocks will not work, but & lt; What about the% # ...%> code block, aka? Data-binding expression page runs in the desired part of the lifecycle and runs DataBind inside the call. However, here is the operative word expression is a if
statement is not expression; You can not enter anything between and <% # ...%>
Expression will be evaluated by the compiler if you have made a statement there, then the compiler throws an error.
So we Eval to Visible on data-binding Access the phrase of expression in the expression A control property Eval data binding expression An expression is consistent with expression; writing an expression is enough to specify the value of a property; And the visible property is able to get the same effect as using an inline if
statement Last tip: If you ever end up in a situation where you have naturally If there is no current control to add the visible position, then you can always use it, which does not add any tag to the markup.
Comments
Post a Comment