Datagrid Cancle/update button calles delete command?

Discussion in 'ASP .Net Datagrid Control' started by cjb@goldmancg.com, Aug 24, 2005.

  1. Guest

    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
     
    , Aug 24, 2005
    #1
    1. Advertising

  2. Guest

    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.
     
    , Aug 24, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elliot M. Rodriguez

    suppressing Submit command with a Delete button

    Elliot M. Rodriguez, Dec 16, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    448
    Elliot M. Rodriguez
    Dec 17, 2003
  2. lovecreatesbeauty
    Replies:
    2
    Views:
    419
    codigo
    Apr 25, 2005
  3. MU
    Replies:
    0
    Views:
    530
  4. prakash
    Replies:
    2
    Views:
    595
    prakash
    Apr 11, 2005
  5. sindre
    Replies:
    7
    Views:
    256
    Michael Schmitt
    Jul 2, 2004
Loading...

Share This Page