Googler

两情相悦,又岂在朝朝暮暮。

asp.net 实体类赋值

View Code
private const string ScriptSetFunction = "(function(o,v){o=document.getElementById(o)||document.getElementsByName(o)[0];if(o)o.value=v;return arguments.callee;})";

public static void SetHtmlPost(Page page, object entity)
{
StringBuilder script
= new StringBuilder(ScriptSetFunction);
foreach (PropertyAccess property in EntityUtility.GetEnumerable(entity))
{
object value = property.GetValue(entity);
if (value != null)
{
script.AppendFormat(
"('{0}','{1}')", property.MappedName, value);
}
}
page.ClientScript.RegisterStartupScript(page.GetType(),
string.Empty, script.Append(";").ToString(), true);
}

public static void GetHtmlPost(Page page, object entity)
{
foreach (PropertyAccess property in EntityUtility.GetEnumerable(entity))
{
string value = page.Request.Form[property.MappedName];
if (value != null)
{
property.SetValue(entity, property.ChangeType(value));
}
}
}

posted on 2011-04-06 09:22  RockyLOMO  阅读(796)  评论(0编辑  收藏  举报

导航

Apple/苹果笔记本 Mac Air MC968CH/A 行货在保 I5 11寸 超级本