C
cj
I have created a datagrid with both EditCommandColumn and ButtonColumn
(setup as Delete). Even when I change the Delete command to a different name
"Remove", the "Cancel" button always ends up doing the 'Delete/Remove'
subroutine
What is happening with this? I searched on the net and only found one
similar occurance, but no answer Surely it is a known problem..?
Below is some of my code.
Any help out there (I've spent hours trying to nut this out...)?
Thanks
cj
<asp:datagrid
id="dgSoldItems"
runat="server"
AutoGenerateColumns="False"
EnableViewState="False"
ForeColor="Black"
BackColor="White"
CellPadding="3"
CellSpacing="1"
Font-Size="X-Small"
GridLines="None"
DataKeyField="SaleItemID"
OnEditCommand="dgSoldItems_Edit"
OnCancelCommand="dgSoldItems_Cancel"
OnUpdateCommand="dgSoldItems_Update"
OnDeleteCommand="dgSoldItems_Delete"<ItemStyle
backcolor="#DEDFDE"></ItemStyle>
<HeaderStyle font-bold="True"
forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
<Columns>
<asp:EditCommandColumn
EditText="Edit" CancelText="Cancel" UpdateText="Update"
ItemStyle-Wrap="false" ButtonType="PushButton"/>
<asp:ButtonColumn Text="Remove Item"
CommandName="Delete" ButtonType="PushButton"/>
<asp:BoundColumn DataField="ItemID"
HeaderText="Item ID" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="Price"
HeaderText="Price" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:BoundColumn
DataField="ProductName" HeaderText="Product Name"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="ModelNumber" HeaderText="Model Number"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="SerialNumber" HeaderText="Serial Number"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="AssetNumber" HeaderText="Asset Number"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="SaleID"
HeaderText="SaleID" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="SaleItemID" HeaderText="SaleItemID"
ReadOnly="True"></asp:BoundColumn>
</Columns>
</asp:datagrid>
Sub dgSoldItems_Edit(Sender As Object, E As DataGridCommandEventArgs)
dgSoldItems.EditItemIndex = CInt(E.Item.ItemIndex)
BinddgSoldItems()
End Sub
Sub dgSoldItems_Cancel(Sender As Object, E As DataGridCommandEventArgs)
dgSoldItems.EditItemIndex = -1
BinddgSoldItems()
End Sub
Sub dgSoldItems_Update(Sender As Object, E As DataGridCommandEventArgs)
End Sub
Sub dgSoldItems_Delete(Sender As Object, E As DataGridCommandEventArgs)
Dim DelItemCommand As SqlCommand
Dim DeleteCmdText As String = "DELETE from Sold_Items where
SaleItemID = @SaleItemID"
DelItemCommand = New SqlCommand(DeleteCmdText, MyConnection)
Dim dbParam_SaleItemID As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_SaleItemID.ParameterName = "@SaleItemID"
dbParam_SaleItemID.Value =
dgSoldItems.DataKeys(CInt(E.Item.ItemIndex))
dbParam_SaleItemID.DbType = System.Data.DbType.Int32
DelItemCommand.Parameters.Add(dbParam_SaleItemID)
DelItemCommand.Connection.Open()
Try
DelItemCommand.ExecuteNonQuery()
lblmsg.Text = "<b>Record [SaleItemID=" &
dgSoldItems.DataKeys(CInt(E.Item.ItemIndex)) & "] Deleted</b>"
Catch Exc As SQLException
lblmsg.Text = "ERROR: Could not delete record"
End Try
DelItemCommand.Connection.Close()
BinddgSoldItems()
End Sub
(setup as Delete). Even when I change the Delete command to a different name
"Remove", the "Cancel" button always ends up doing the 'Delete/Remove'
subroutine
What is happening with this? I searched on the net and only found one
similar occurance, but no answer Surely it is a known problem..?
Below is some of my code.
Any help out there (I've spent hours trying to nut this out...)?
Thanks
cj
<asp:datagrid
id="dgSoldItems"
runat="server"
AutoGenerateColumns="False"
EnableViewState="False"
ForeColor="Black"
BackColor="White"
CellPadding="3"
CellSpacing="1"
Font-Size="X-Small"
GridLines="None"
DataKeyField="SaleItemID"
OnEditCommand="dgSoldItems_Edit"
OnCancelCommand="dgSoldItems_Cancel"
OnUpdateCommand="dgSoldItems_Update"
OnDeleteCommand="dgSoldItems_Delete"<ItemStyle
backcolor="#DEDFDE"></ItemStyle>
<HeaderStyle font-bold="True"
forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
<Columns>
<asp:EditCommandColumn
EditText="Edit" CancelText="Cancel" UpdateText="Update"
ItemStyle-Wrap="false" ButtonType="PushButton"/>
<asp:ButtonColumn Text="Remove Item"
CommandName="Delete" ButtonType="PushButton"/>
<asp:BoundColumn DataField="ItemID"
HeaderText="Item ID" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="Price"
HeaderText="Price" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:BoundColumn
DataField="ProductName" HeaderText="Product Name"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="ModelNumber" HeaderText="Model Number"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="SerialNumber" HeaderText="Serial Number"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="AssetNumber" HeaderText="Asset Number"
ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="SaleID"
HeaderText="SaleID" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn
DataField="SaleItemID" HeaderText="SaleItemID"
ReadOnly="True"></asp:BoundColumn>
</Columns>
</asp:datagrid>
Sub dgSoldItems_Edit(Sender As Object, E As DataGridCommandEventArgs)
dgSoldItems.EditItemIndex = CInt(E.Item.ItemIndex)
BinddgSoldItems()
End Sub
Sub dgSoldItems_Cancel(Sender As Object, E As DataGridCommandEventArgs)
dgSoldItems.EditItemIndex = -1
BinddgSoldItems()
End Sub
Sub dgSoldItems_Update(Sender As Object, E As DataGridCommandEventArgs)
End Sub
Sub dgSoldItems_Delete(Sender As Object, E As DataGridCommandEventArgs)
Dim DelItemCommand As SqlCommand
Dim DeleteCmdText As String = "DELETE from Sold_Items where
SaleItemID = @SaleItemID"
DelItemCommand = New SqlCommand(DeleteCmdText, MyConnection)
Dim dbParam_SaleItemID As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_SaleItemID.ParameterName = "@SaleItemID"
dbParam_SaleItemID.Value =
dgSoldItems.DataKeys(CInt(E.Item.ItemIndex))
dbParam_SaleItemID.DbType = System.Data.DbType.Int32
DelItemCommand.Parameters.Add(dbParam_SaleItemID)
DelItemCommand.Connection.Open()
Try
DelItemCommand.ExecuteNonQuery()
lblmsg.Text = "<b>Record [SaleItemID=" &
dgSoldItems.DataKeys(CInt(E.Item.ItemIndex)) & "] Deleted</b>"
Catch Exc As SQLException
lblmsg.Text = "ERROR: Could not delete record"
End Try
DelItemCommand.Connection.Close()
BinddgSoldItems()
End Sub