asp.net - if else statement within formview -


I have a form that is, it provides fields from an SQLServer database, but it is specific to the database value that I get it. I do not know that it can be done behind the code and can put all this in a function. I put it in my form view

  & lt; Item template & gt; & Lt;% If Eval ("Feature1") = "Yes" then% & gt; & Lt;% # Eval ("Username")% & gt; & Lt; P & gt; Too many lessons & lt; / P & gt; & Lt;% elseIf Eval ("Feature1") = "No" then% & gt; & Lt;% # Eval ("Username")% & gt; & Lt; P & gt; Too many different text & lt; / P & gt; & Lt;% end if% & gt; & Lt; / ItemTemplate & gt;  

If I code above, I get an error message:

Database methods such as Eval (), XPath (), and Bind ( ) Can be used only in the context of a database control, can it be done within your presentation?

Many thanks for your help.

You can use DataBinder.Eval as follows:

  & lt;% if (DataBinder.Eval (formview.DataItem, "first") == "yes") {%> & Lt; P & gt; Too many lessons & lt; / P & gt; & Lt;%} Other {%> & Lt; P & gt; Too many different text & lt; / P & gt; & Lt;%}% & gt;  

If you have a postback, you should store the DataItem anywhere and instead it will replace the DataBinder.Eval parameter As it should be used because it becomes zero.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -