Datagrid Cancle/update button calles delete command?

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

  1. #1

    Default Datagrid Cancle/update button calles delete command?

    Hi,

    I'm trying to extend the DataGrid class, and I think I am getting my
    wires crossed.

    In the constructor I add my colums:

    Public Sub New()
    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
    Services=-4; Data Source=" + HttpContext.Current.Server.MapPath(".\") +
    "picPost.mdb;"
    HeaderStyle.BackColor =
    System.Drawing.Color.FromArgb(CType("&H999966", Integer))
    ItemStyle.BackColor =
    System.Drawing.Color.FromArgb(CType("&HAAC1F8", Integer))
    AlternatingItemStyle.BackColor =
    System.Drawing.Color.FromArgb(CType("&HFFFF99", Integer))
    EditItemStyle.BackColor =
    System.Drawing.Color.FromArgb(CType("&HEEEEEE", Integer))
    itemCreatedIteration = 0
    Dim editColumn As System.Web.UI.WebControls.EditCommandColumn =
    New System.Web.UI.WebControls.EditCommandColumn()
    Dim deleteColumn As System.Web.UI.WebControls.ButtonColumn =
    New System.Web.UI.WebControls.ButtonColumn()
    Dim eventColumn As System.Web.UI.WebControls.BoundColumn = New
    BoundColumn()
    Dim indexColumn As System.Web.UI.WebControls.BoundColumn = New
    BoundColumn()


    ''Setupt the delteColumn
    deleteColumn.ButtonType = ButtonColumnType.PushButton
    deleteColumn.CommandName = "Delete"
    deleteColumn.Text = "Remove"
    ''Setup the EditCommand Column
    editColumn.EditText = "Edit"
    editColumn.ButtonType = ButtonColumnType.PushButton
    editColumn.CancelText = "Cancle"
    editColumn.UpdateText = "Update"
    ''setup the bound columns
    indexColumn.DataField = "pk_event"
    indexColumn.Visible = False
    eventColumn.DataField = "EventName"
    eventColumn.HeaderText = "Bound Events"
    ''Add the new columns
    Columns.Add(indexColumn)
    Columns.Add(eventColumn)
    Columns.AddAt(Columns.Count, editColumn)
    Columns.AddAt(Columns.Count, deleteColumn)
    AutoGenerateColumns = False
    ShowFooter = True
    populateGrid()

    ''OnEditCommand="DG_Events_Edit"
    OnCancelCommand="DG_Events_Cancel" OnDeleteCommand="DG_Events_Delete"

    End Sub

    Then I extend the built in event handlers

    Protected Overrides Sub OnDeleteCommand(ByVal e As
    DataGridCommandEventArgs)
    MyBase.OnDeleteCommand(e)
    HttpContext.Current.Response.Write("got Delete <br />")
    Dim indexToDelete As Integer
    indexToDelete = CType(e.Item.Cells(0).Text, Integer)
    DeleteEvent(indexToDelete)
    populateGrid()

    End Sub
    Protected Overrides Sub OnEditCommand(ByVal E As
    DataGridCommandEventArgs)
    MyBase.OnEditCommand(E)
    Me.EditItemIndex = E.Item.ItemIndex
    HttpContext.Current.Response.Write("got the editCommand")
    DataBind()

    End Sub
    Protected Overrides Sub OnCancelCommand(ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs )
    MyBase.OnCancelCommand(e)
    Me.EditItemIndex = -1
    populateGrid()
    End Sub

    My problem is, Edit gets called just fine, delete gets called just
    fine, but when I hit cancel, ondeletecommand gets called, and when I
    hit update ondeletecommand gets called.

    I also added a button add, and the events work fine for that.

    Can anyone shed any light on my mistake?

    Thanks,

    CJB

    cjb@goldmancg.com Guest

  2. Similar Questions and Discussions

    1. Datagrid item renderer delete button
      I have a datagrid with an item renderer. In the item renderer is a delete button img. Onclick it will remove the item from the datagrid with the...
    2. Datagrid Update Command
      Any help PLEASE! I have a datagrid on a aspx page. The editcommand and cancelcommand work as explected however my updatecommand is not. My...
    3. delete button problems in datagrid
      i have a datagrid with a delete button which for some reason quit working, i'm thinking its a problem with the database but here is the code:...
    4. 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
    5. Trigger Datagrid Edit From Command Button
      Hey all, I was wanting to know if this was possible. I have a Datagrid with inline editing capabilites and all that jazz, it all works. What I...
  3. #2

    Default Re: Datagrid Cancle/update button calles delete command?

    My Problem was here:
    Protected Overrides Sub OnEditCommand(ByVal E As
    DataGridCommandEventArgs)
    MyBase.OnEditCommand(E)
    Me.EditItemIndex = E.Item.ItemIndex
    HttpContext.Current.Response.Write("got the editCommand")
    DataBind()

    End Sub
    My DataBind() should have been populateGrid, which is were I populate
    the dataset.

    cjb@goldmancg.com 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