一个好的网站建设服务商一定会告诉你,表单名称和对象的属性名要保持一样,你的网站建设平台有些不安全了,不过后台使用是没问题的,填写表单数据后台用的比较多。具体如下:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.Reflection;
usingSystem.Collections.Specialized;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
///
///通过对象设置获取表单值
///
namespaceCom.Fun
{
publicstaticclassSetFormToModel
{
///
///将表单赋予对对象
///
///实体对象
///表单集合
publicstaticvoidGetValue(Tt,NameValueCollectionform)
{
Typetype=t.GetType();
PropertyInfo[]pi=type.GetProperties();
foreach(PropertyInfopinpi)
{
if(form[p.Name]!=null)
{
p.SetValue(t,Convert.ChangeType(form[p.Name],p.PropertyType),null);
}
}
}
///
///将对象赋予表单
///
///实体对象
///页面对象
publicstaticvoidSetValue(Tt,Pagepage)
{
Typetype=t.GetType();
PropertyInfo[]pi=type.GetProperties();
foreach(PropertyInfopinpi)
{
System.Web.UI.HtmlControls.HtmlInputTexttext=page.FindControl(p.Name)asSystem.Web.UI.HtmlControls.HtmlInputText;
if(text!=null)
{
text.Value=http://www.jzxue.com/wangzhankaifa/asp-net/201011/p.GetValue(t,null).ToString();
}
}
}
}
}
//调用
MHouseRecomh=newDHouseReco().GetModel(id);
Com.Fun.SetFormToModel.SetValue(mh,this.Page);
MHouseRecomh=newMHouseReco();
Com.Fun.SetFormToModel.GetValue(mh,this.Request.Form);
这是一个非常好的杭州网站建设蒙特人团队为大家精心分享的网站建设知识,希望大家在碎片之余,能够关注一下。知识不在多少,在于我们日常能积累和沉淀多少,这样好的知识,希望大家都不会错过!免费的,没错,我们依旧每天愿意准时与大家分享网站建设的秘籍和法宝!
©2000-2022 杭州蒙特信息技术有限公司版权所有
Mountor、蒙特是Mountor Corp.的注册商标。