Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete button not working

Status
Not open for further replies.

knaya

MIS
Dec 4, 2003
51
US
yup, stuck again.. helppp.. i have a simple datagrid, no paging, its has 3 columns, a author, booktitle and price and it loads data depending on if the user has books posted.. what i'm trying to do is allow the user to delete his books if its been sold.. i have a delete button in the datagrid but when i hit it, nothing happens, it doesnt even delete the record from the database.. below is my code if anyone can tell me what i'm doing wrong.. muchos graciousss

Sub dgrdTitles_Delete(Sender As Object, E As DataGridCommandEventArgs)
Dim conbooks As OleDbConnection
Dim isEditing As Boolean = False

If Not isEditing Then

Dim keyValue As String = CStr(dgrdtitles.DataKeys(e.Item.ItemIndex))

conbooks = new OleDbConnection ( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\accounts\jackb\test.mdb")
Dim DeleteCommand As New OleDbCommand("DELETE from online where author='" & keyValue & "'", conbooks)

conbooks.Open()
DeleteCommand.ExecuteNonQuery()
conbooks.Close()


End If

End Sub


<asp:datagrid id="dgrdtitles" runat="server" Width="471px" Height="169px" PageSize="3" AutoGenerateColumns="False"
OnDeleteCommand="DataGrid_Delete">
<HeaderStyle Font-Names="Times New Roman" Font-Bold="True" HorizontalAlign="Center" ForeColor="Maroon"></HeaderStyle>
<PagerStyle BorderWidth="1px" BorderColor="Red" BorderStyle="Dashed" BackColor="MistyRose"></PagerStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="booktitle" HeaderText="Book Title"></asp:BoundColumn>
<asp:BoundColumn DataField="author" HeaderText="Author"></asp:BoundColumn>
<asp:BoundColumn DataField="price" HeaderText="Book Price" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid></P>
 
My DeleteCommand needed the Handles... after it so that the event was called. My HTML looked just like yours for the Delete button.

Sub dgGrid_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgGrid.DeleteCommand


Hope everyone is having a great day!

Thanks - Jennifer
 
Jennifer,
so glad you're online :).. i tried that but its not working, i'm feeling very retarded right now.. its giving me a compilation error:Handles clause requires a WithEvents variable

this is what i changed:Sub Datagrid_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Datagrid.DeleteCommand

helppp, i'm thought this would be real simple but its starting to drive me crazyyy
 
someone helppp, i cant get this too work.. i've tried everything and it still gives me the same error
 
Can you place a breakpoint in the event? Does it reach that point?

Hope everyone is having a great day!

Thanks - Jennifer
 
IIRC i had this or something similar, and it was to do with rebinding the datagrid every time the page was refreshed, have you got your datagrid binding inside an
(!IsPostback) ?

I was altering my datagrid, then as it was redrawn, it refreshed the data and so the button did not appear to work

hth

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top