和之间有什么区别 [英] what's the difference between and

查看:155
本文介绍了和之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经通过嵌入cs代码来制作动态css,如下所示:

i used to make a dynamic css by embed cs code, like so:

<div class="<%# Request.RawUrl.Contains(" personinformation.aspx=") ? " xx=" : " zh_x_z=" %>" /div>



不起作用,但以下情况起作用:



doesn''t work, but the following does:

<div class="<%= Request.RawUrl.Contains(" personinformation.aspx=") ? " xx=" : " zh_x_z=" %>" /div>




您能告诉我




can you tell me the reason or principle of that

推荐答案

"<%# %>"是DataBinding表达式的原因或原理吗?另一方面,<%=%>是一个仅在服务器中作为Response.Write(")执行并在浏览器中输出内容的表达式.

假设您使用具有DataSource属性的Server控件,并且该控件是基于模板(GridView,DataList等)的Server控件.现在,如果您将该控件的数据源与某些兼容数据(例如集合)绑定,则可以在运行时将该数据源中的对象的属性绑定到控件模板中的控件.请参阅 http://msdn.microsoft.com/en-us/library/ms178366.aspx [ ^ ]了解更多信息.

在您的情况下,您想根据条件输出您的类名.因此,您应该使用<%=%>"表达式,因此可以正常工作.
显然,由于您在此处未使用任何基于模板的服务器控件,并且未绑定任何数据源.因此,数据绑定表达式<%#%>"无法正常工作.
"<%# %>" is a DataBinding expression. On the other hand, <%= %> is an expression that simply executes in server as Response.Write("") and outputs something int the browser.

Suppose you use a Server control that has a DataSource property and this is Template based (GridView,DataList etc) Server control. Now if you bind the datasource of that control with some compatible data (Say, a collection), at runtime, you can bind a property of an object within that datasource to a control within the template of the control. See http://msdn.microsoft.com/en-us/library/ms178366.aspx[^] to learn more.

In your case, you want to output your class name based upon a condition. So, you should yous "<%= %>" expression and hence, this is working.
Obviously, as you are not using any Template based Server control here and you are not binding any datasource. So, the databinding expression "<%# %>" is not working.


这篇关于和之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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