ActiveRecord与GridView,ObjectDataSource配合使用时的问题
当一个对象的对象属性经ObjectDataSource绑定到GridView时,在他进行CRUD操作时就会变成空或new出来的新对象。
因此在作Crud操作时需要将它重新赋值。
我首先在ObjectDataSource1_Updating1中赋值,但系统提示InputParameters只读不能赋值,
后来我在GridView1_RowUpdating中赋值。终于成功。
protected void ObjectDataSource1_Updating1(object sender, ObjectDataSourceMethodEventArgs e)
{
//BaseBanjiStudent stu = (BaseBanjiStudent)e.InputParameters["obj"];
//stu.BaseBanji = BaseBanji.Find(long.Parse(this.ddlBanji.SelectedValue));
//e.InputParameters.Remove("obj");
//e.InputParameters["obj"] = stu;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
e.NewValues["BaseBanji"] = BaseBanji.Find(long.Parse(this.ddlBanji.SelectedValue));
}
{
//BaseBanjiStudent stu = (BaseBanjiStudent)e.InputParameters["obj"];
//stu.BaseBanji = BaseBanji.Find(long.Parse(this.ddlBanji.SelectedValue));
//e.InputParameters.Remove("obj");
//e.InputParameters["obj"] = stu;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
e.NewValues["BaseBanji"] = BaseBanji.Find(long.Parse(this.ddlBanji.SelectedValue));
}