[ת]dz̸.NETÖеÄÊý¾Ý°ó¶¨±í´ïʽ(¶þ)
1£¬Êý¾Ý°ó¶¨·½·¨µÄÀ´Ô´ÒÔ¼°ÔڵͲãÉϵÄʵÏÖ¡£
2£¬Êý¾Ý°ó¶¨·½·¨µÄÖ´ÐÐЧÂÊÅÅÐò¡£
<%#Container.DataItem%>
<%#GetDataItem()%>
<%#Eval("×Ö¶ÎÃû")%>
<%#DataBinder.Eval(Container.DataItem,"×Ö¶ÎÃû")%>
<%#((DataRowView)Container.DataItem)["×Ö¶ÎÃû"] %>
<%#((Type)Container.DataItem).³ÉÔ± %>
<%#((Type)GetDataItem()).³ÉÔ± %>
ÉÏÃæÆßÖÖ°ó¶¨ÐÎʽÒÔ¼°ËüÃǵıä»ÃÐÎʽ¶¼ÓùýÂð£¿ÐÔÄÜÔõôÅÅÐò£¿
¸´Ï°Ò»Ï£ºµÚÒ»½ÚÎÒÃÇÖ÷Ҫ̸ÁËÊý¾Ý°ó¶¨±í´ïʽµÄ¸÷ÖÖÐÎʽ£¬ÔÚASP.NETÒ³ÃæÖгöÏÖµÄλÖã¬ÒÔ¼°ÎÒÃdz£°ó¶¨µ½ÓëÊý¾Ý¿âÓйصÄDataView,DataTable,DataSet µÈÊý¾ÝÔ´µÄÊý¾Ý°ó¶¨±í´ïʽµÄ¸÷ÖÖÐÎʽ¡£
ÄãÓÐûÓжÔEval·½·¨ºÍDataBinder.Eval·½·¨ºÃÆæ¹ý£¿
ÔÚ.NET2.0ÖÐÎÒÃǾ³£ÓÃEval·½·¨ÔÚRepeater,DataList,GridViewµÈÑ»·¿Ø¼þÖаó¶¨Êý¾Ý£¬Eval·½·¨ºÍDataBinder.Eval·½·¨ÔڵͲãÊÇÔõôʵÏֵģ¿ËüÃǵ½µ×ÓÐʲôǧ˿ÍòÂƵĹØϵ£¿
Ò»£¬À´Ô´¡¢ÊµÏÖ¡£
ÎÒ
Ãdz£ÓõÄEval·½·¨ÆäʵÊÇPageÀàµÄÒ»¸ö¾²Ì¬µ¥ÏòÖ»¶Á·½·¨£¬¶øÇÒËüÊÇÒ»¸öÊܱ£»¤µÄ·½·¨¡£Êµ¼ÊÉÏPageÀàµÄEval·½·¨ÊǼ̳Ð×Ô
TemplateControlÀàµÄ¡£TemplateControl ÀàÊÇÒ»¸ö³éÏóÀ࣬ËüΪPage ÀàºÍ UserControl
ÀàÌṩͨÓÃÊôÐԺͷ½·¨¡£ÎÒÃÇÏÈÀ´¿´Ò»Ï¼̳мÒÆ×£º
System.Object
System.Web.UI.Control
System.Web.UI.TemplateControl
System.Web.UI.Page
System.Web.UI.UserControl
Eval·½·¨¾ÍÊÇTemplateControlÀàµÄ·½·¨£¬ËüÓÐÁ½ÖÖÐÎʽ£º
Ãû³Æ | ˵Ã÷ |
TemplateControl.Eval (String) | ¼ÆËãÊý¾Ý°ó¶¨±í´ïʽ¡£ |
TemplateControl.Eval (String, String) | ʹÓÃÓÃÓÚÏÔʾ½á¹ûµÄÖ¸¶¨¸ñʽ×Ö·û´®¼ÆËãÊý¾Ý°ó¶¨±í´ïʽ¡£ |
ÊÂʵÉÏTemplateControlÀ໹ÌṩÁËXPath·½·¨ºÍXPathSelect·½·¨¹©PageÀàºÍUserControl¼Ì³Ð¡£Õâ2¸ö·½·¨ÊǺÍXMLÊý¾ÝÔ´Óйصİ󶨷½·¨¡£
Èç¹ûϸÐĵÄÄã²é¿´TemplateControlÀàµÄ»ùÀàControlÀ࣬Äã¾Í»á·¢ÏÖÆäʵControlÀಢûÓÐÌṩEval,XPath,XPathSelectµÈ·½·¨¡£ËùÒÔEval£¬XPathµÈ·½·¨×îÖÕÊÇÔÚTemplateControlÀàÖÐʵÏֵġ£
ÏÖÔÚ£¬ÖÕÓÚÕÒµ½ÁËEval£¬XPathµÈÊý¾Ý°ó¶¨·½·¨µÄÀ´Ô´ÁË¡£
Eval,XPathµÈ·½·¨ÊÇ.NET 2.0ÐÂÔöµÄ·½·¨¡£ÔÚ.NET 1.1ʱ´úÎÒÃǾ³£ÓõÄÊÇDateBinder.Eval·½·¨¡£ÐÎÈ磺
<%#DataBind.Eval(Container.DataItem,"×Ö¶ÎÃû") %> <%#DataBind.Eval(Container.DataItem,"×Ö¶ÎÃû","{0:c}") %>EvalµÄ³öÏÖÆäʵ¾ÍÊÇΪÁ˼ò»¯DataBinder.Eval·½·¨µÄд·¨´Ó¶ø´úÌæËü¡£
ÔÚASP.NET 2.0Öм°ÒÔÉÏ£¬µ±ÎÒÃǵ÷ÓÃEvalʱ£¬Eval ·½·¨»áʹÓÃGetDataItem·½·¨µ÷ÓÃDataBinder.Eval·½·¨¼ÆËã±í´ïʽµÄÖµ¡£ÒªÏëÀí½âÕâ¾ä»°£¬¾ÍËã²é±ßMSDNҲһͷÎíË®£¬³ý·ÇÎÒÃÇÖªµÀEval·½·¨µÄÔ´´úÂ룬·ñÔò¸ù±¾ÕÒ²»µ½ÖëË¿Âí¼£¡£ÕâÀï¾ÍÒªÓõ½·´ÉäÁË¡£ÎÒÃÇͨ¹ý·´Éä»ñµÃÁËEval·½·¨µÄÔ´´úÂ룺
ÖÕÓÚ¼ûµ½GetDataItem()·½·¨ÁË£¬Æä
ʵËü¾ÍÊÇPageÀàµÄÒ»¸ö·½·¨£¬Ò²ÊÇ.NET
2.0ÐÂÔöÒ»¸ö·½·¨¡£GetDataItem()·½·¨µÄ×÷ÓÃÊÇΪÁË»ñµÃContainer.DataItem£¬ËüÊÇ.NET
2.0ÖÐÓÃÀ´´úÌæContainer.DataItemµÄ£¬Èç¹ûÄãÔø¾ÓÃRepeaterºÍDataListµÈ°ó¶¨¹ýÊý×é»òÕßArrayListµÈ£¬Äã¾Í
»á·¢ÏÖ<%#GetDataItem()%>ºÍ<%#Container.DataItem%>µÈ¼Û¡£protected internal object Eval(string expression)
{
this.CheckPageExists();
return DataBinder.Eval(this.Page.GetDataItem(), expression);
}
ҪŪÇåEvalÊÇÔõô¹¤×÷µÄ£¬GetDataItem()·½·¨µÄµÍ²ãʵÏÖÎÒÃÇÒ²ÒªÓ÷´ÉäÀ´»ñÈ¡£º
public object GetDataItem()
{
if ((this._dataBindingContext == null) || (this._dataBindingContext.Count == 0))
{
throw new InvalidOperationException(SR.GetString("Page_MissingDataBindingContext"));
}
return this._dataBindingContext.Peek();
}
ÎÒÃÇ´ÓGatDataItem()·½·¨Öп´µ½¡°return this._dataBindingContext.Peek();¡±ºÜ¿ì¾Í²ÂÏë_dataBindingContextÊDz»ÊÇÒ»¸ö¶ÑÕ»ÄØ£¿ÊÂʵËü¾ÍÊÇÒ»¸ö¶ÑÕ»£¡Í¨¹ý·´Éä²é¿´Ô´´úÂëÎÒÃǵóö£º_dataBindingContextÊÇÒ»¸öStackÀàÐͶÔÏó¡£ËùÒÔËüÓÐPeek·½·¨¡£¡°return this._dataBindingContext.Peek(); ¡±ÕýÊǰѶÑÕ»¶¥²¿µÄÔªËØ·µ»Ø¡£¶øifÓï¾äÊÇÓÃÀ´ÅжÏÕâ¸ö¶ÑÕ»ÊÇ·ñÒѾ´æÔÚ»òÕßÊÇ·ñÒѾÓÐÔªËØ´æÔÚ£¬Èç¹ûif²»³ÉÁ¢£¬¾Í»áÅ׳öÒ»¸öÒì³£¡£
´ÓÉÏÃæµÄ·ÖÎöÎÒÃÇÖªµÀ£º_dataBindingContext¶ÑÕ»µÄ×÷ÓÃÊÇͨ¹ýGetDataItem()·½·¨Õâ¸öÇÅÁºÏòEval·½·¨ÌṩContainer.DateItem¡£ÓÃÄæÏò˼άÀ´Àí½âÉÏÃæÕâ¾ä»°£ºEval·½·¨¿ÉÒÔ×Ô¶¯¼ÆËã³öContainer.DataItem£¬ÔÒò¾ÍÊÇ´ÓdataBindingContext
¶ÑÕ»À´»ñÈ¡Container.DataItem£»ÕâÒ²¾ÍΪʲôEval·½·¨Äܹ»ÖªµÀÐÎÈç<%#Eval"×Ö¶ÎÃû"%>ÖÐ×Ö¶ÎÃûÁ¥ÊôÓÚÄĸöÊý
¾ÝÏîµÄÊôÐÔµÄÔÒò£»Í¬Ê±ÎÒÃÇÒ²ÖªµÀ.NET
2.0ÖеÄEvalÔÚ±¾ÖÊÉϵÄʵÏÖ²¢Ã»ÓÐÅ×ÆúContainer.DataItem£¬¶øContainer.DataItemÔÚ2.0ʱ´úҲûÓÐÏûʧ¡£
ÄÇô_dataBindingContextÕâ¸ö±£´æContainer.DataItemµÄ¶ÑÕ»ÊÇÔõô½¨Á¢µÄÄØ£¿
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- Asp.net MVCÔ´Âë·ÖÎö--Model Validation(Se....
- .Net À¬»ø»ØÊÕ»úÖÆÔÀíºÍËã·¨£¨Ò»£©
- .netʵÌåнâ
- ·ÖÎöASP.NET¶ÁÈ¡XMLÎļþ4ÖÖ·½·¨
- »ñÈ¡ÍøÕ¾ËõÂÔͼ´úÂë
- Asp.net ¸ù¾ÝIPµØÖ·»ñÈ¡¿çÍø¶ÎmacµØÖ·º¯Êý¡¾ËѲء¿
- ¹ýÂËÃô¸Ð¹Ø¼ü×Ö¡£
- Éú³ÉÖ¸¶¨Î»ÊýµÄËæ»ú×Ö·û´®
- ¿Í»§¶Ë»ñÈ¡MACµØÖ·£¬µ½·þÎñÆ÷ÑéÖ¤
- ²½²½ÎªÓª .NETÈý²ã¼Ü¹¹½âÎö ¶þ¡¢Êý¾Ý¿âÉè¼Æ
ÆÀÂÛ