Mass delete (with checkboxes / delete all link)

Last post 09-03-2008 2:59 AM by qualiarunner. 2 replies.

Sort Posts:

  • Mass delete (with checkboxes / delete all link)

    09-02-2008, 10:57 AM
    • Member
      29 point Member
    • qualiarunner
    • Member since 06-13-2006, 10:29 AM
    • Posts 9

    Hi,

     I've been trying to add mass delete linkbutton to a template page. It was easy to add checkboxes / gather IDs on postback, and I even found method that looks promising: LinqDataSource.Delete(IDictionary keys,IDictionary oldKeys)

    All that I get is InvalidCastException: cannot get from System.Int32 to System.String

     

    I know it's not strictly dynamic data question, but I can think of the situation as extending standard templates that DynamicData uses. Are there some specific requirements that 'keys' must adhere to, other than hashtable (simplest object implementing IDictionary) containing IDs to delete? I'm not sure too about that second oldKeys param.

    Filed under:
  • Re: Mass delete (with checkboxes / delete all link)

    09-02-2008, 1:11 PM
    • Member
      194 point Member
    • chenriks
    • Member since 09-27-2006, 5:07 PM
    • Redmond, WA
    • Posts 50

    The DataSource Delete, Insert and Update methods only support operating on a single row at a time.  The IDictionary arguments should take string column names as the keys and column values as the values.

    You will need to do some custom logic in order to delete multiple rows at a time.  You can do this be handling the DataBoundControl's OnRowDeleting or OnItemDeleting event and setting e.Cancel=true when you have completed the operation (so that the data source doesn't perform the delete).  Alternatively you could handle the DataSource's OnDeleting event, but this is only called after successfully creating a data object from the input dictionaries for a single row.

    Christy Henriksson
    ASP.NET Team
  • Re: Mass delete (with checkboxes / delete all link)

    09-03-2008, 2:59 AM
    • Member
      29 point Member
    • qualiarunner
    • Member since 06-13-2006, 10:29 AM
    • Posts 9

    What I did - traverse rows collection and issue LinqDataSource.Delete individually for each checked row and that works fine.

    Thanks


Page 1 of 1 (3 items)