ObjectDatasource Deletemethod w custom Business Object [modified]
-
Hi, I've tried to create a business object that can fully bind to the ObjectDatasource to be used in a DetailsView object for example. Everything works f X| ine here, but I cannot seem to get the deletemethod to do anything. This is the testobject I created: public class BO { private int _id = 0; public int Id { get { return _id; } set { _id = value; } } private string _Field = string.Empty; public string Field1 { get { return _Field; } set { _Field = value; } } private string _Field2 = string.Empty; public string Field2 { get { return _Field2; } set { _Field2 = value; } } public BO() { } public BO(string fld1, string fld2) { Field1 = fld1; Field2 = fld2; } public BO LoadMe() { return (HttpContext.Current.Session["bo"] != null)?(BO)HttpContext.Current.Session["bo"]:new BO(); } public void AddMe(BO bo) { HttpContext.Current.Session["bo"] = bo; } public void DeleteMe(BO bo) { BO InMem = (HttpContext.Current.Session["bo"] != null) ? (BO)HttpContext.Current.Session["bo"] : new BO(); if (InMem.Id == bo.Id) // Why is bo empty ?? HttpContext.Current.Session["bo"] = new BO(); } I created a page with an objectdatasource, selecting LoadMe as the SELECT method, AddMe() as the INSERT method, and DeleteMe() as the DELETE method. The odd thing is that DeleteMe() fires, but the parameter bo is passed with just empty values.. Does anyone know what I'm doing wrong (if I'm doing something wrong) ? Never mind the working of the object, I just need the Delete method to work. tia, Patt -- modified at 10:37 Thursday 22nd June, 2006
-
Hi, I've tried to create a business object that can fully bind to the ObjectDatasource to be used in a DetailsView object for example. Everything works f X| ine here, but I cannot seem to get the deletemethod to do anything. This is the testobject I created: public class BO { private int _id = 0; public int Id { get { return _id; } set { _id = value; } } private string _Field = string.Empty; public string Field1 { get { return _Field; } set { _Field = value; } } private string _Field2 = string.Empty; public string Field2 { get { return _Field2; } set { _Field2 = value; } } public BO() { } public BO(string fld1, string fld2) { Field1 = fld1; Field2 = fld2; } public BO LoadMe() { return (HttpContext.Current.Session["bo"] != null)?(BO)HttpContext.Current.Session["bo"]:new BO(); } public void AddMe(BO bo) { HttpContext.Current.Session["bo"] = bo; } public void DeleteMe(BO bo) { BO InMem = (HttpContext.Current.Session["bo"] != null) ? (BO)HttpContext.Current.Session["bo"] : new BO(); if (InMem.Id == bo.Id) // Why is bo empty ?? HttpContext.Current.Session["bo"] = new BO(); } I created a page with an objectdatasource, selecting LoadMe as the SELECT method, AddMe() as the INSERT method, and DeleteMe() as the DELETE method. The odd thing is that DeleteMe() fires, but the parameter bo is passed with just empty values.. Does anyone know what I'm doing wrong (if I'm doing something wrong) ? Never mind the working of the object, I just need the Delete method to work. tia, Patt -- modified at 10:37 Thursday 22nd June, 2006
-
That worked. Thanks. Eh, you wouldn't know how to keep it working even if I set the ID field readonly ?
Another option is that you can create the handler for the
Deleting
event of the ObjectDataSource control, in the handler you can set the Id or whatever property of the BO object stored in thee.InputParameters
collection, this object is then passed to the Delete method as the parameter.