Accessing data object on delete command.

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Accessing data object on delete command.

    Hi guys.

    I have a datagrind that is bound to a custom collection of a custom
    object.

    When a delete button is pressed in the datagrid, I not only want to
    remove the row from the grid, I want to delete the object from the
    collection that is bound to the grid.

    So far I have this.

    public void groupsGrid_DeleteCommand(object sender,
    DataGridCommandEventArgs e)
    {


    try
    {
    //My Group object UMGroup grouptodelete =
    (UMGroup)e.Item.DataItem;

    // attempt delete
    groupsCollection.Remove(grouptodelete);

    }

    catch(Exception exp)
    {
    Errortxt.Text = exp.Message;
    }

    //Disable Edit mode
    groupsGrid.EditItemIndex = -1;

    //Refresh data in grid
    PopulateDatagrid();
    }

    My problem is, grouptodelete comesback with object undefined. Is there
    away of getting access to the object that is supplying data to the row
    that fired the delete command?

    Thanks
    Amit
    Cappy Guest

  2. Similar Questions and Discussions

    1. how to delete some of the history data in chatcomponent shared object
      Hi, i have made a chat application using chat component, but the chat component store the data permanentely in the server, How to delete the...
    2. Delete form - Post data to a table and delete uponsubmit.
      I have a delete form that I'd like to post the data to a table (delete_pcn) and delete upon submit, so that all deletions may be kept track of in...
    3. ASP/VBS Using Command to Insert/Update/Delete
      Hi, I would just like to know when/why etc would you command and if there any penalties in using the command. Thanks, Sanjay
    4. Accessing DataRow Items by Name in Edit/Update/Delete Event
      Hi there. I have a small problem with DataGrid in ASP.NET & C#. In the ItemDataBound Event I can use the following code DataRowView drvSE =...
    5. unix command to delete parts of a file
      hello all! I'd like to ask if there's a unix command that could delete parts of the file given a string. Example: Given: File1 which contains...
  3. #2

    Default Accessing data object on delete command.

    Hi Cappy,

    In order to delete the object, you should get it first.
    Suppose you have a key for the custom object. You can get
    the key in couple of ways:

    string key = datagrid.DataKeys[e.Item.ItemIndex];
    string key = e.Item.Cells[key_Column_Index].Text; // for
    BoundColumn
    string key = ((contrl_type)e.Item.FindControl
    ("key_Column_ID")).Text; // for TemplateColumn

    Then you can get your custom object by the key:
    UMGroup grouptodelete = method_of_find_object(key);
    // then delete the object
    if (grouptodelete != null)
    {
    groupsCollection.Remove(grouptodelete);

    }

    HTH


    Elton Wang
    [email]elton_wang@hotmail.com[/email]

    >-----Original Message-----
    >Hi guys.
    >
    >I have a datagrind that is bound to a custom collection
    of a custom
    >object.
    >
    >When a delete button is pressed in the datagrid, I not
    only want to
    >remove the row from the grid, I want to delete the object
    from the
    >collection that is bound to the grid.
    >
    >So far I have this.
    >
    >public void groupsGrid_DeleteCommand(object sender,
    >DataGridCommandEventArgs e)
    > {
    >
    >
    > try
    > {
    > //My Group object
    UMGroup
    grouptodelete =
    >(UMGroup)e.Item.DataItem;
    >
    > // attempt delete
    > groupsCollection.Remove
    (grouptodelete);
    >
    > }
    >
    > catch(Exception exp)
    > {
    > Errortxt.Text =
    exp.Message;
    > }
    >
    > //Disable Edit mode
    > groupsGrid.EditItemIndex = -1;
    >
    > //Refresh data in grid
    > PopulateDatagrid();
    > }
    >
    >My problem is, grouptodelete comesback with object
    undefined. Is there
    >away of getting access to the object that is supplying
    data to the row
    >that fired the delete command?
    >
    >Thanks
    >Amit
    >.
    >
    Elton W Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139