"若"在FormView的标记条件 [英] "if" Conditions in Formview Markup

查看:186
本文介绍了"若"在FormView的标记条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个表格视图来显示学生的成绩单。成绩单将有额外的列,如果是从第二项和2个列的成绩单,如果从第三学期。要了解它是长期的,我需要评估TermNumber属性,并显示相应的标题。这是我的标志高达code:

I want to show a student report card using a form view. The report card will have additional columns, if it is a report card from 2nd term and 2 more columns, if its from 3rd term. To find out which term it is, I need to evaluate the TermNumber Property, and show the appropriate heading. This is my mark up code:

<% if ((int)Eval("TermNumber") == 2) %>
<% { %>
    <th> 1st Term Score</th>
<% } %>
<% else if ((int)Eval("TermNumber") == 3) %>
<% { %>
    <th> 1st Term Score</th>
    <th> 2nd Term Score</th>
<% } %>

这将导致运行时错误:数据绑定方法如的eval(),XPath的()和b​​ind()只能在数据绑定控件的上下文中使用

This results in run time Error : Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

这是因为评估和演示只能是与LT的一部分;%#%>标签

This is because Eval can only be part of a <%# %> tag.

&使用LT;%#%>在编译时错误,并且VS13智能感知的结果,表示其无效项

Using <%# %> results in compile time error, and the VS13 intellisense, says its invalid term.

我的问题是:我如何才能在实现有条件地显示列我的目标成功。我可以使用,如果条件中的数据绑定控件的标记?或者有没有其他的方式来实现这一目标,而无需每一项创建单独的formviews。

My Question is: How can I succeed in achieving my target of conditionally showing the columns. Can I use the if Condition in the markup of the Databound controls? Or is there any other way to achieve this, without creating separate formviews for each term.

表单视图,还具有Repeater控件来显示科目的分数,也需要利用的,如果条件。

The Form View, also has a repeater control to show the subject scores, and also needs to utilise the if Condition.

推荐答案

所以我回答我的问题。由于从鲁本的接受的答案的提示:的eval在if语句

So I am answering my own question. Thanks to the hint from Ruben's Accepted answer at: eval in if statement?

<th runat="server" visible='<%# (int)Eval("TermNumber") > 1 %>'>1st Term Score</th>
<th runat="server" visible='<%# (int)Eval("TermNumber") > 2 %>'>2nd Term Score</th>

这也适用无中继器控制的任何问题。
与RUNAT Visible属性=服务器不包括任何标记,在最后的输出,它完美的罚款。和code也更优雅,如果块。

This also works without any problems in the repeater control. As the Visible property with runat="Server" doesn't includes any markup, in the final output, it works perfectly fine. and the code is also more elegant the if blocks.

这篇关于&QUOT;若&QUOT;在FormView的标记条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆