473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DataGrid OnDeleteCommand Problem

Hi,

I've been trying to get a button to delete a record from the DataGrid
for absolutely ages and have had no luck. At the moment clicking on
the delete button does nothing. I have no idea what I'm doing wrong.
Hopefully someone can help me out!

<form id="myform" runat="server" method="post">
<asp:datagrid id="dgBasket" runat="server"
OnPageIndexChanged="Page_Change" OnDeleteCommand="dgBasket_Delete"
OnEditCommand="MyDataGrid_Edit" OnCancelCommand="MyDataGrid_Cancel"
OnUpdateCommand="MyDataGrid_Update" CellPadding="2" BackColor="White"
BorderColor="#CCCCCC" BorderWidth="0px" BorderStyle="None"
AutoGenerateColumns="False" width="100%"
AlternatingItemStyle-BackColor="#dddddd">
<FooterStyle forecolor="#000066"
backcolor="White"></FooterStyle>
<HeaderStyle font-size="Smaller" font-names="Verdana"
font-bold="True" forecolor="White" backcolor="Navy"></HeaderStyle>
<PagerStyle horizontalalign="Left" forecolor="#000066"
backcolor="White" mode="NumericPages"></PagerStyle>
<SelectedItemStyle font-bold="True" forecolor="White"
backcolor="#669999"></SelectedItemStyle>
<AlternatingItemStyle
backcolor="#DDDDDD"></AlternatingItemStyle>
<ItemStyle font-names="Arial" forecolor="#000066"
backcolor="Silver"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="ItemID"
ReadOnly="True" HeaderText="Code">
<ItemStyle
horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ItemName"
ReadOnly="True" HeaderText="Name">
<HeaderStyle width="10cm"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:Label id="lblQty" runat="server"
text='<%# DataBinder.Eval(Container.DataItem, "qty") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" id="txtQty"
Text='<%# DataBinder.Eval(Container.DataItem, "qty") %>' />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ItemPrice"
ReadOnly="True" HeaderText="Price" DataFormatString="{0:c}">
<HeaderStyle width="3cm"></HeaderStyle>
</asp:BoundColumn>
<asp:ButtonColumn Text="Delete"
ButtonType="PushButton"
CommandName="DeleteFromCart"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="PushButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:datagrid>
I have a delete function on the aspx page but it never gets called. I
have other functions to deal with the edit commands, which are in a
code behind file. Here is the delete function.

Sub dgBasket_Delete( ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs )
Dim OrderNumber as String
Dim cellNumber as String
Dim objGetData as new Cart()

OrderNumber = session("sorderNbr").tostring()
cellNumber = e.item.cells(0).text
objGetData.deleteFromCart(cellNumber, OrderNumber)
response.redirect("Stock.aspx")
End Sub
Nov 18 '05 #1
2 2506
In CommandName you write "DeleteFromCart" Use the word "Delete" only.

I hope this will help you.

Regards
Ather Ali Shaikh
"Defty" <it*****@aol.com> wrote in message
news:c9**************************@posting.google.c om...
Hi,

I've been trying to get a button to delete a record from the DataGrid
for absolutely ages and have had no luck. At the moment clicking on
the delete button does nothing. I have no idea what I'm doing wrong.
Hopefully someone can help me out!

<form id="myform" runat="server" method="post">
<asp:datagrid id="dgBasket" runat="server"
OnPageIndexChanged="Page_Change" OnDeleteCommand="dgBasket_Delete"
OnEditCommand="MyDataGrid_Edit" OnCancelCommand="MyDataGrid_Cancel"
OnUpdateCommand="MyDataGrid_Update" CellPadding="2" BackColor="White"
BorderColor="#CCCCCC" BorderWidth="0px" BorderStyle="None"
AutoGenerateColumns="False" width="100%"
AlternatingItemStyle-BackColor="#dddddd">
<FooterStyle forecolor="#000066"
backcolor="White"></FooterStyle>
<HeaderStyle font-size="Smaller" font-names="Verdana"
font-bold="True" forecolor="White" backcolor="Navy"></HeaderStyle>
<PagerStyle horizontalalign="Left" forecolor="#000066"
backcolor="White" mode="NumericPages"></PagerStyle>
<SelectedItemStyle font-bold="True" forecolor="White"
backcolor="#669999"></SelectedItemStyle>
<AlternatingItemStyle
backcolor="#DDDDDD"></AlternatingItemStyle>
<ItemStyle font-names="Arial" forecolor="#000066"
backcolor="Silver"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="ItemID"
ReadOnly="True" HeaderText="Code">
<ItemStyle
horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ItemName"
ReadOnly="True" HeaderText="Name">
<HeaderStyle width="10cm"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:Label id="lblQty" runat="server"
text='<%# DataBinder.Eval(Container.DataItem, "qty") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" id="txtQty"
Text='<%# DataBinder.Eval(Container.DataItem, "qty") %>' />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ItemPrice"
ReadOnly="True" HeaderText="Price" DataFormatString="{0:c}">
<HeaderStyle width="3cm"></HeaderStyle>
</asp:BoundColumn>
<asp:ButtonColumn Text="Delete"
ButtonType="PushButton"
CommandName="DeleteFromCart"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="PushButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:datagrid>
I have a delete function on the aspx page but it never gets called. I
have other functions to deal with the edit commands, which are in a
code behind file. Here is the delete function.

Sub dgBasket_Delete( ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs )
Dim OrderNumber as String
Dim cellNumber as String
Dim objGetData as new Cart()

OrderNumber = session("sorderNbr").tostring()
cellNumber = e.item.cells(0).text
objGetData.deleteFromCart(cellNumber, OrderNumber)
response.redirect("Stock.aspx")
End Sub

Nov 18 '05 #2
Hi,

Thanks alot for your help. It worked straight away!

Cheers,
James
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fortra | last post by:
I'm having trouble with the UpdateCommand event with the DataGrid control. The event is wired up in the InitializeComponents properly, this.sitesDataGrid.UpdateCommand += new...
0
by: shamila | last post by:
</asp:label><asp:datagrid id="DataGrid3" runat="server" cssclass="DataGrid" showfooter="True" onupdatecommand="DataGrid3_Update"ondeletecommand="DataGrid3_Delete" oneditcommand="DataGrid3_Edit"...
0
by: Curtis Hatter | last post by:
I apologize if this has been answered, but on the .NET 247 site I saw a thread titled "Datagrid's ItemCommand Event", and had similar troubles with the Datagrid not properly firing the delete event...
4
by: moondaddy | last post by:
I have a datagrid where a user can edit a number in one of the columns for a quantity value. On the postback I loop through all of the datagrid items and if the quantity has changed, then I update...
1
by: Joe | last post by:
Hi, I have form with datagrid. This is what my form tag looks like, <form runat="server"> <asp:label runat="server" id="lblMessage" /> <asp:DataGrid runat="server" id="articleList"...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
4
by: glenn | last post by:
Hi folks, I am getting an error "Object reference not set to an instance of an object". It seems I have everything in place but something is obviously in err. If you could take a quick peak...
2
by: tshad | last post by:
I am having a problem with my Datagrid that displays my Files via GetFiles() If I use a HyperLinkColumn - I can use the column name "Name" which is what the result from GetFiles(). ...
2
by: Iain | last post by:
Hi All Using Delphi 2006 developer - C# Project I have the following 2 event handlers for the datagrid - see botton of page Both events will fire off correctly but i have a problem collecting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.