一個好的網(wǎng)站建設(shè)服務(wù)商一定會告訴你,表單名稱和對象的屬性名要保持一樣,你的網(wǎng)站建設(shè)平臺有些不安全了,不過后臺使用是沒問題的,填寫表單數(shù)據(jù)后臺用的比較多。具體如下:
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;
///
///通過對象設(shè)置獲取表單值
///
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();
}
}
}
}
}
//調(diào)用
MHouseRecomh=newDHouseReco().GetModel(id);
Com.Fun.SetFormToModel.SetValue(mh,this.Page);
MHouseRecomh=newMHouseReco();
Com.Fun.SetFormToModel.GetValue(mh,this.Request.Form);
這是一個非常好的杭州網(wǎng)站建設(shè)蒙特人團隊為大家精心分享的網(wǎng)站建設(shè)知識,希望大家在碎片之余,能夠關(guān)注一下。知識不在多少,在于我們?nèi)粘D芊e累和沉淀多少,這樣好的知識,希望大家都不會錯過!免費的,沒錯,我們依舊每天愿意準(zhǔn)時與大家分享網(wǎng)站建設(shè)的秘籍和法寶!
©2000-2022 杭州蒙特信息技術(shù)有限公司版權(quán)所有
Mountor、蒙特是Mountor Corp.的注冊商標(biāo)。