Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. ObjectDatasource Deletemethod w custom Business Object [modified]

ObjectDatasource Deletemethod w custom Business Object [modified]

Scheduled Pinned Locked Moved ASP.NET
businesstutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patt
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • P patt

      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

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Do you set the ID field in the DataKeyNames property of the DetailsView control?

      P 1 Reply Last reply
      0
      • M minhpc_bk

        Do you set the ID field in the DataKeyNames property of the DetailsView control?

        P Offline
        P Offline
        patt
        wrote on last edited by
        #3

        That worked. Thanks. Eh, you wouldn't know how to keep it working even if I set the ID field readonly ?

        M 1 Reply Last reply
        0
        • P patt

          That worked. Thanks. Eh, you wouldn't know how to keep it working even if I set the ID field readonly ?

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          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 the e.InputParameters collection, this object is then passed to the Delete method as the parameter.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups