且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

和之间有什么区别

更新时间:2022-06-22 05:39:31

"<%# %>"是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.