您的位置:首页 > 其它

关于.net Web开发及WinForm数据绑定实例

2008-10-17 11:25 477 查看
用.net做web开发,相当简单,会操作数据库,会用一些服务器控件就可以了,当然,我相信,你对三层开发,面向对象也挺熟悉吧,理解这些,你会发现,其实做web开发,与做桌面程序,并没有什么大的差别,数据层与逻辑层甚至可以与原来的桌面程序通用(实际跟据业务情况不同,可能会有改动)。

从winform转变过来搞webform的程序,基本不需要学什么的,但是,你得保证,你所在的团队是个专业的开发团队,也就是说,在表示层有专人负责,(刚说了,数据层与逻辑层没什么大变化)。

在表示层,要处理的事情很多,如果没有专人负责,你所在的团队不够专业,可能你要做很多东西,例如HTML,CSS,Javascript这些基本东西,你都得会。
还有XML,XSLT,XMLHTTP(这些技术合起来叫Ajax)等,都会接触到。你会发现,学这些东西远比C#更容易,但工作起来,它远比C#更让你烦。

所以,如果你的团队不够专业,分工不够明细,会把你烦死。

------以下为一个winFrom开发 数据绑定实例----------

以下为一个类:::
using System;
using System.Collections.Generic;
using System.Text;

namespace AppBindingContext
{
public class Person
{
private string _lastName;

public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
private string _firstName;

public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
private int _age;

public int Age
{
get { return _age; }
set { _age = value; }
}
public Person() { }
public Person(string lastName, string firstName, int age)
{
this.LastName = lastName;
this.FirstName = firstName;
this.Age = age;
}
}
}

WinForm数据绑定

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AppBindingContext
{
public partial class Form1 : Form
{
//声明一个管理者
private CurrencyManager cm;
public Form1()
{
InitializeComponent();
//建立数据源集合.
List<Person> list = new List<Person>();
list.Add(new Person("LastName1", "FirstName1", 30));
list.Add(new Person("LastName2", "FirstName2", 31));
list.Add(new Person("LastName3", "FirstName3", 32));
list.Add(new Person("LastName4", "FirstName4", 33));
//数据绑定
this.textBox1.DataBindings.Add("Text", list, "LastName");
this.textBox2.DataBindings.Add("Text", list, "FirstName");
this.textBox3.DataBindings.Add("Text", list, "Age");
this.dataGridView1.DataSource = list;
//通过指定的数据源对象获得相应的CurrencyManager对象.
cm = (CurrencyManager)this.BindingContext[list];
}
//点击此按钮可以导航到上一条记录
private void button1_Click(object sender, EventArgs e)
{
cm.Position--;
}
//点击此按钮可以导航到下一条记录
private void button2_Click(object sender, EventArgs e)
{
cm.Position++;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: