Register / Login
Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
this forum made possible by our volunteer staff, including ...
Stephan van Hulst
C# and .NET
Other Application Frameworks
How to add a delete button in datalist/datatable (VB.NET)?
posted 2 years ago
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.
It is sorta covered in the
JavaRanch Style Guide
Boost this thread!
Convert VB.net to java
Sending a string from vb to java servlet
XML binding to <asp:dropdownlist> declaratively
Doubt in HashMap