Datagrid Cancle/update button calles delete command?

C

cjb

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
 
C

cjb

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top