Deleting rows from listview bases on a value for a column

spiffware

New Member
I got a datatable in list view.ID TelcoName Reload Value(RM) Quantity Total(RM)1 Maxis 5 1 5 Delete2 Digi 5 1 5 DeleteThis is basically what my table looks like.My html code is this:\[code\]<asp:ListView ID="ListView1" runat="server" OnSorting="ListView1Sorting" OnItemCommand="ListView1_ItemCommand"> <LayoutTemplate> <table border="0" cellpadding="1"> <tr style="background-color:#FFFFFF"> <th align="center"><asp:Label ID="lblId" runat="server">Id &nbsp;</asp:Label></th> <th align="center"><asp:Label ID="lblName" runat="server">TelcoName&nbsp;</asp:Label></th> <th align="center"><asp:Label ID="lblReloadValue" runat="server">Reload Value(RM)&nbsp;</asp:Label></th> <th align="center"><asp:Label ID="lblQuantity" runat="server">Quantity&nbsp;</asp:Label></th> <th align="center"><asp:Label ID="lblTotal" runat="server">Total (RM)&nbsp;</asp:Label></th> <th></th> </tr> <tr id="itemPlaceholder" runat="server"></tr> </table> </LayoutTemplate> <ItemTemplate> <tr> <td align="center"><asp:Label runat="server" ID="lblId"><%#Eval("ID") %></asp:Label></td> <td align="center"><asp:Label runat="server" ID="lblTelcoName"><%#Eval("TelcoName") %></asp:Label></td> <td align="center"><asp:Label runat="server" ID="lblReloadValue"><%#Eval("ReloadValue")%></asp:Label></td> <td align="center"><asp:Label runat="server" ID="lblQuantity"><%#Eval("Quantity")%></asp:Label></td> <td align="center"><asp:Label runat="server" ID="lblTotal"><%#Eval("Total")%></asp:Label></td> <td align="center"><asp:LinkButton ID="lnkDelete" runat="server" CommandName="Sort" CommandArgument="Delete">Delete</asp:LinkButton></td> </tr> </ItemTemplate> </asp:ListView>\[/code\]This is my behind code for deleting:Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) If (e.CommandName) = "Sort" Then Dim txteno As Label = DirectCast(e.Item.FindControl("ID"), Label) Dim deletecommand As String = "delete from dt where ID=" & Convert.ToInt32(txteno.text) Session("dt").DeleteCommand = deletecommand End If End SubMy problem here is i coud'nt get the ID of the row which the user choose. The "ID" is the name of the first column but when i run the website, this statement return nothing.Dim txteno As Label = DirectCast(e.Item.FindControl("ID"), Label)My question is how do i retrieve the value of the column("Id") to use for the deleting data? i ask around and someone suggest to me to use e.item.DataItemIndex but i coudnt find this command anywhere. Any idea how to solve this?
 
Back
Top