D
Defty
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
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