[ת]dz̸.NETÖеÄÊý¾Ý°ó¶¨±í´ïʽ(¶þ)(2)
ÎÒ
ÃǺܿì¾ÍÏ뵽ÿ´Î°ó¶¨¿Ø¼þʱºò×îºóÄÇÌõÓï¾äÊÇʲô£ºthis.¿Ø¼þID.DataBind()£»¶Ô¾ÍÊÇDataBind()·½·¨,DataBind()·½
·¨»¹ÓÐÒ»¸öÖØÔØ:DataBind(bool
raiseOnDataBinding)¡£Îª_dataBindingContextÕâ¸ö¶ÑջѹÈëÔªËغ͵¯³öÔªËصķ½·¨ÕýÊÇÓÃDataBind(bool
flag)Õâ¸öÖØÔØ·½·¨ÊµÏֵġ£
DataBind(bool raiseOnDataBinding)ÔڵͲãµÄʵÏÖ£º
protected virtual void DataBind(bool raiseOnDataBinding)
{
bool flag1 = false;//Õâ¸ö±êÖ¾µÄÓô¦ÔÚÉÏÏÂÎÄÖкÜÈÝÒ×ÍƳöÀ´£¬Èç¹ûÓÐDataItemѹջ£¬ÔòÔÚºóÃæ³öÕ»¡£
if (this.IsBindingContainer)//ÅжϿؼþÊDz»ÊÇÊý¾Ý°ó¶¨ÈÝÆ÷£¬Êµ¼ÊÉϾÍÊÇÅжϿؼþÀàÊDz»ÊÇʵÏÖÁËINamingContainer
{
bool flag2;
object obj1 = DataBinder.GetDataItem(this, out flag2);//Õâ¸ö·½·¨ÊÇÅжϿؼþÊDz»ÊÇÓÐDataItemÊôÐÔ£¬²¢°ÑËüÈ¡³öÀ´¡£
if (flag2 && (this.Page != null))//Èç¹û¿Ø¼þÓÐDataItem
{
this.Page.PushDataBindingContext(obj1);//°ÑDataItemѹջ£¬PushDataBindingContext¾ÍÊǵ÷ÓÃ_dataBindingContextµÄPush·½·¨
flag1 = true;
}
}
try
{
if (raiseOnDataBinding)//ÕâÀïÊÇÅжÏÊDz»ÊÇ´¥·¢DataBindingʼþµÄ¡£
{
this.OnDataBinding(EventArgs.Empty);
}
this.DataBindChildren();//¶Ô×ӿؼþ½øÐÐÊý¾Ý°ó¶¨£¬Èç¹ûÕâ¸ö¿Ø¼þÓÐDataItem£¬ÔòÉÏÃæ»á½«DataItemѹÈëÕ»¶¥£¬ÕâÑù£¬ÔÚ×ӿؼþÀïÃæµ÷ÓÃEval»òÕßGetDataItem·½·¨£¬¾Í»á°Ñ¸Õ¸Õѹ½øÈ¥µÄDataItem¸øÈ¡³öÀ´¡£
}
finally
{
if (flag1)//Èç¹û¸Õ²ÅÓÐѹջ£¬ÔòÏÖÔÚµ¯³öÀ´¡£
{
this.Page.PopDataBindingContext();//PopDataBindingContext¾ÍÊǵ÷ÓÃ_dataBindingContextµÄPop·½·¨
}
}
}
µ±ÎÒÃÇÖ´Ðе½this.¿Ø¼þID.DataBind();ʱºò¡£ÔڵͲãÉϾͻáµ÷ÓÃÕâ¸öÖØÔصķ½·¨À´×¼±¸°üº¬DataItemµÄ_DatBindingContext¶ÑÕ»¡£
ÉÏÃæµÄ´úÂëÖÐÌáµ½ÁËDataBindingʼþ£¬ÄÇôËüÒ»°ãʲôʱºò±»´¥·¢ÄØ£¿
£±£¬Èç¹ûÓñà³Ì·½Ê½£¬ÄÇôÔÚÎÒÃǵ÷ÓÃDataBind()·½·¨Ê±ºò×Ô¶¯´¥·¢DataBindingʼþ¡£
£²£¬Èç¹ûÎÒÃÇÓÃÊý¾ÝÔ´¿Ø¼þ£¨ÀýÈçSqlDataSourceµÈ£©£¬µ±°Ñ¿Ø¼þ°ó¶¨µ½Êý¾ÝÔ´¿Ø¼þʱºò£¬Õâ¸öʼþ¾Í»á×Ô¶¯´¥·¢¡£
Ò»°ãÊý¾Ý°ó¶¨±í´ïʽ³£³£·ÅÔÚÄ£°åÖÐÑ»·ÏÔʾÊý¾Ý£¬ÀýÈçRepeaterºÍDataListµÈµÄÄ£°å¡£ÄÇôÏÂÃæÕâ¸ö֪ʶµãÓ¦¸ÃÖªµÀ£ºRepeater£¬DataList£¬FormViewµÈ¿Ø¼þ±ØÐëʹÓÃÄ£°å£¬Èç¹û²»Ê¹ÓÃÄ£°å£¬ÕâЩ¿Ø¼þ½«ÎÞ·¨ÏÔʾÊý¾Ý¡£¶øGridView£¬DetailsView£¬MenuµÈ¿Ø¼þÒ²Ö§³ÖÄ£°å£¬µ«ÏÔʾÊý¾Ýʱ²»ÊDZØÐëµÄ¡£¶øTreeView¿Ø¼þ²»Ö§³ÖÄ£°å¡£
×¢Ò⣺һ°ãÇé¿öÏ£¬Êý¾Ý°ó¶¨±í´ïʽ²»»á×Ô¶¯¼ÆËãËüµÄÖµ£¬³ý·ÇËüËùÔÚµÄÒ³»òÕ߿ؼþÏÔʾµ÷ÓÃDataBind()·½·¨¡£DataBind()·½·¨Äܹ»½«Êý¾ÝÔ´°ó¶¨µ½±»µ÷ÓõķþÎñÆ÷¿Ø¼þ¼°ÆäËùÓÐ×ӿؼþ£¬Í¬Ê±·ÖÎö²¢¼ÆËãÊý¾Ý°ó¶¨±í´ïʽµÄÖµ¡£
ÖÕÓÚдµÄÓеãüĿÁË£¬ºÃÀÛ£¡ÎÒÃǸûØÍ·¿´¿´Eval·½·¨µ÷Óõľ²Ì¬DataBinder.Eval·½·¨ÔڵͲãµÄʵÏÖÁË¡£ÎÒ°ÑDataBinderÀàµÄÔ´´úÂëÌù³öÀ´£º
namespace System.Web.UI
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
[PermissionSet(SecurityAction.LinkDemand, XML = "<PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\">\r\n <IPermission class=\"System.Web.AspNetHostingPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n version=\"1\"\r\n Level=\"Minimal\"/>\r\n</PermissionSet>\r\n")]
public sealed class DataBinder
{
private static readonly char[] expressionPartSeparator = new char[] { '.' };
private static readonly char[] indexExprEndChars = new char[] { ']', ')' };
private static readonly char[] indexExprStartChars = new char[] { '[', '(' };
public static object Eval(object container, string expression)
{
if (expression == null)
{
throw new ArgumentNullException("expression");
}
if (container == null)
{
return null;
}
string[] expressionParts = expression.Trim().Split(expressionPartSeparator);
return Eval(container, expressionParts);
}
private static object Eval(object container, string[] expressionParts)
{
object propertyValue = container;
for (int i = 0; (i < expressionParts.Length) && (propertyValue != null); i++)
{
string propName = expressionParts[i];
if (propName.IndexOfAny(indexExprStartChars) < 0)
{
propertyValue = GetPropertyValue(propertyValue, propName);
}
else
{
propertyValue = GetIndexedPropertyValue(propertyValue, propName);
}
}
return propertyValue;
}
public static string Eval(object container, string expression, string format)
{
object obj2 = Eval(container, expression);
if ((obj2 == null) || (obj2 == DBNull.Value))
{
return string.Empty;
}
if ((format != null) && (format.Length != 0))
{
return string.Format(format, obj2);
}
return obj2.ToString();
}
public static object GetIndexedPropertyValue(object container, string expr)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
if ((expr == null) || (expr.Length == 0))
{
throw new ArgumentNullException("expr");
}
object obj2 = null;
bool flag = false;
int length = expr.IndexOfAny(indexExprStartChars);
int num2 = expr.IndexOfAny(indexExprEndChars, length + 1);
if (((length < 0) || (num2 < 0)) || (num2 == (length + 1)))
{
throw new ArgumentException(HttpRuntime.FormatResourceString("DataBinder_Invalid_Indexed_Expr", expr));
}
string propName = null;
object obj3 = null;
string s = expr.Substring(length + 1, (num2 - length) - 1).Trim();
if (length != 0)
{
propName = expr.Substring(0, length);
}
if (s.Length != 0)
{
if (((s[0] == '"') && (s[s.Length - 1] == '"')) || ((s[0] == '\'') && (s[s.Length - 1] == '\'')))
{
obj3 = s.Substring(1, s.Length - 2);
}
else if (char.IsDigit(s[0]))
{
try
{
obj3 = int.Parse(s, CultureInfo.InvariantCulture);
flag = true;
}
catch (Exception)
{
obj3 = s;
}
}
else
{
obj3 = s;
}
}
if (obj3 == null)
{
throw new ArgumentException(HttpRuntime.FormatResourceString("DataBinder_Invalid_Indexed_Expr", expr));
}
object propertyValue = null;
if ((propName != null) && (propName.Length != 0))
{
propertyValue = GetPropertyValue(container, propName);
}
else
{
propertyValue = container;
}
if (propertyValue == null)
{
return obj2;
}
if ((propertyValue is Array) && flag)
{
return ((object[])propertyValue)[(int)obj3];
}
if ((propertyValue is IList) && flag)
{
return ((IList)propertyValue)[(int)obj3];
}
PropertyInfo info = propertyValue.GetType().GetProperty("Item", BindingFlags.Public | BindingFlags.Instance, null, null, new Type[] { obj3.GetType() }, null);
if (info == null)
{
throw new ArgumentException(HttpRuntime.FormatResourceString("DataBinder_No_Indexed_Accessor", propertyValue.GetType().FullName));
}
return info.GetValue(propertyValue, new object[] { obj3 });
}
public static string GetIndexedPropertyValue(object container, string propName, string format)
{
object indexedPropertyValue = GetIndexedPropertyValue(container, propName);
if ((indexedPropertyValue == null) || (indexedPropertyValue == DBNull.Value))
{
return string.Empty;
}
if ((format != null) && (format.Length != 0))
{
return string.Format(format, indexedPropertyValue);
}
return indexedPropertyValue.ToString();
}
public static object GetPropertyValue(object container, string propName)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
if ((propName == null) || (propName.Length == 0))
{
throw new ArgumentNullException("propName");
}
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(container).Find(propName, true);
if (descriptor == null)
{
throw new HttpException(HttpRuntime.FormatResourceString("DataBinder_Prop_Not_Found", container.GetType().FullName, propName));
}
return descriptor.GetValue(container);
}
public static string GetPropertyValue(object container, string propName, string format)
{
object propertyValue = GetPropertyValue(container, propName);
if ((propertyValue == null) || (propertyValue == DBNull.Value))
{
return string.Empty;
}
if ((format != null) && (format.Length != 0))
{
return string.Format(format, propertyValue);
}
return propertyValue.ToString();
}
}
}
¶þ£¬Ö´ÐÐЧÂÊ
´Ó¡°Ò»¡±½²ÊöµÄµÍ²ãʵÏÖ¡£ÎÒÃǺÜÈÝÒ×À´ÅÅÐòÏÂÃæÊý¾Ý°ó¶¨±í´ïʽµÄÖ´ÐÐЧÂÊ
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- 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Èý²ã¼Ü¹¹½âÎö ¶þ¡¢Êý¾Ý¿âÉè¼Æ
ÆÀÂÛ