我的ListView1包含以下内容:
<ItemTemplate>
<tr style="text-align: center">
<td>Notification:
<asp:Label Text='<%# Eval("NotificationID") %>' runat="server" ID="NotificationIDLabel" Visible="False" />
<asp:Label Text='<%# Eval("CustomerID") %>' runat="server" ID="CustomerIDLabel" Visible="False" />
<asp:Label Text='<%# Eval("NotificationText") %>' runat="server" ID="NotificationTextLabel" /></td>
<td>
<asp:HyperLink ID="hlPromo" NavigateUrl='<%# Eval("URL") %>' ForeColor="#701A3C" runat="server">View</asp:HyperLink></td>
<td>
<asp:Button ID="btnDeleteNotification" runat="server" Text="Clear" ForeColor="#701A3C" BorderStyle="None" BackColor="#331700" /></td>
</tr>
</ItemTemplate>
我将btnDeleteNotification更改为选定的索引更改,因为我想找出要在SQL表中删除的NotificationID。我怎么能抓住所选行的NotificationID?我已经尝试过VB的所有组合,我可以想到抓住它。
提前致谢!
答案 0 :(得分:1)
在FindControl()
事件中使用SelectedIndexChanged
,如下所示:
Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim theNotificationLabel As Label = CType(ListView1.Items(ListView1.SelectedIndex).FindControl("NotificationIDLabel"), Label)
' Grab the ID from the text of the label
Dim theNotificationId As Integer = Convert.ToInt32(theNotificationLabel.Text)
End Sub
注意:如果您的列表视图未命名为
ListView1
,请将其更改为列表视图实际命名的任何内容。