I am making a website using vb .net
I have a datalist which has a datatable and delete button. the output llooks some thing like this below. 'X' is the delete button.
---------------------
| X name1 | X name3 |
| X name2 | X name4 |
---------------------
When user click on the delete button(X) i want to get the id of that button and use that to delete a record in database.
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" RepeatLayout="Table" DataKeyField="ID" OnDeleteCommand="DataList1_DeleteCommand">
<ItemTemplate>
<asp:ImageButton ID="imgdeletebtn" ImageUrl="x-icon.png" runat="server" />
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
</ItemTemplate>
</asp:DataList>
Protected Sub DataList1_DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs)
Dim getID As Integer = CInt(DataList1.DataKeys(CInt(e.Item.ItemIndex)))
ErrorL.Text = getID
Dim deletedQuery As String = "DELETE FROM [table_name] WHERE [ID] = '" & getID & "'"
End Sub
i am new to VB .net and I cant seem to figure this out. I want to send the id in back end so i can delete that record.