首 页 | 模 板 | 学 院 | 源 码 | 书 籍 | 壁 纸 | 字 体 | JS脚本 | FLASH源码 | 软 件 | 矢 量 | 服务器软件 | 素 材 | 其 它 |
设为主页
加入收藏
联系站长
平面设计 | 网页制作 | 程序编写 | 数 据 库 | 媒体动画 | 网络冲浪 | 服务器相关 | 站长乐园 | 业界动态 |
当前在线
用反射将业务对象绑定到ASP.NET
2006-11-24 11:56:41  作者:模板天下收集整理  来源:未知 网友评论 0 条 论坛
  

MSDN上面的代码和下载的代码包也有那么多问题,晕死。
综合下载的代码和MSDN上的说明,修改了这段代码,现在能正常使用,特别是很多字段放在窗体上的时候,使用起来非常方便。

具体用法:把窗体上的控件ID属性与实体层的属性设置成一致。
绑定实体层到窗体的时候用:
web.model .test Test = new web.model.test();
Test = bll.GetModel(id);
BindObjectToControls(model,this);

要把窗体数据绑定到实体层的时候用:
BindControlsToObject(model,this);

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Reflection;

namespace WEB
{
/// <summary>
/// A class with two static methods <see cref="BindObjectToControls"/> and <see cref="BindControlsToObject"/>
/// used to bind the values of and object's properties with web <see cref="Control"/>s that have their
/// ID property set to the name of the object property.
/// </summary>
public class FormBinding
{
/// <summary>
/// Binds an object's properties to <see cref="Control"/>s with the same ID as the propery name.
/// </summary>
/// <param name="obj">The object whose properties are being bound to forms Controls</param>
/// <param name="container">The control in which the form Controls reside (usually a Page or ContainerControl)</param>
public static void BindObjectToControls(object obj, Control container)
{
if (obj == null) return;

// Get the properties of the business object
//
Type objType = obj.GetType();
PropertyInfo[] objPropertiesArray = objType.GetProperties();

foreach (PropertyInfo objProperty in objPropertiesArray)
{

共分5页  [1] [2] [3] [4] [5] 

>> 相关文章

关于网站 | 客服中心 | 服务条款 | 友情链接 | 广告联系 | 本站历程 | 网站导航

吉ICP备05000107号