惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - ji yang

页面点击分析工具设计与实现 使用FreeMind代替PowerPoint做演示 Velocity 2011大会归来 通过扩展属性为SqlServer的索引添加注释信息 memcached对中文key的支持 更安全的服务器:Windows账号权限修改监控 网站活跃用户统计的思路与设计 以服务的方式提供站点基础功能支持 safari的url地址转义问题 fastdfs dotnet 客户端发布 go lang web项目的部署与发布 从设计图到HTML页面时的注意点 关于加班 关于Google App Engine SOA中国路线图活动感受 文章被转载了 Asp.net中基类页的设计和使用 产品营销上的求同策略
一个简单的Spring.net绑定例子
ji yang · 2007-10-19 · via 博客园 - ji yang

下午的时候碰到一个需求,同事需要根据数据库里的表,自动在Aspx Page上添加相应的TextBox控件,并将值绑定到TextBox文本框上,同样的,在保存时也希望能保存回数据库。

为了支持双向绑定,用Spring.net的

Spring.DataBinding.BaseBindingManager来做是个简单的方法,碰到的问题是:Spring.net的绑定表达式是基于属性的,而动态加入的txtName, txtAge是无法通过"Page.txtName", "Page.txtAge"来访问的,即我们动态加入的控件被放到了Page.Form.Controls里了。

解决的办法很简单,为页面加入this["name"]方式的属性访问器:

 public Control this[string name]
 {
  get { return this.FindControl(name); } 
  }

在绑定表达式只要这样写即可:

['name'].Text ,由此把动态加入的控件看着Page的this["name"]属性。

完整的例子代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using Spring.DataBinding;public class People
{
    
string name;
    
public string Name
    {
        
get { return name; }
        
set { name = value; }
    }
}
public partial class PollutionManage_Spring : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        
if (!IsPostBack)
        {
            BaseBindingManager manager 
= new BaseBindingManager();

            TextBox box 

= new TextBox();
            box.Text 
= "hello";
            box.ID 
= "hi";
            
this.Form.Controls.Add(box);

            People p 

= new People();
            p.Name 
= "jiyang";

            manager.AddBinding(

"Name""['hi'].Text");

            manager.BindSourceToTarget(p, 

thisnull);
        }
    }
public Control this[string name] 
    { 
        
get { return this.FindControl(name); } 
    }
}