终于,用Castle调试出类似Hello,World功能。
当正确的结果出来后,感觉比较震撼。实现同样的功能,代码少得令人难以置信。
以下代码是显示一个GridView,包括新增功能。
还有很多问题要慢慢摸索。
User.cs
using System;
using Castle.ActiveRecord;
using NHibernate.Expression;
// This is file is provided just as a starting point
// especially if you are new to ActiveRecord
//
// Feel free to delete it right away.
namespace ARExamWithAspnet
{
[ActiveRecord("Users")]
public class user : ActiveRecordBase<user>
{
private int _LogonID;
private string _LogonName;
private string _Password;
private string _EmailAddress;
private DateTime _LastLogon;
[PrimaryKey]
public int LogonID
{
get { return _LogonID; }
set { _LogonID = value; }
}
[Property]
public string LogonName
{
get { return _LogonName; }
set { _LogonName = value; }
}
[Property]
public string Password
{
get { return _Password; }
set { _Password = value; }
}
[Property]
public string EmailAddress
{
get { return _EmailAddress; }
set { _EmailAddress = value; }
}
[Property]
public DateTime LastLogon
{
get { return _LastLogon; }
set { _LastLogon = value; }
}
}
}
Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
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 ARExamWithAspnet;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//LastLogon.Text = DateTime.Now.ToShortDateString();
BindData();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
user testUser = new user();
FormBinding.BindControlsToObject(testUser, this);
testUser.Create();
BindData();
}
catch (Exception x)
{
Response.Write(x.ToString());
}
}
protected void BindData()
{
this.GridView1.DataSource = user.FindAll();
this.GridView1.DataBind();
}
}
本文分享了使用Castle框架实现类似于Hello,World功能的经验,通过少量代码实现了GridView展示及新增功能。文章详细展示了具体的代码实现,并记录了调试过程中的心得。
2828

被折叠的 条评论
为什么被折叠?



