从列表视图中的标签中获取文本



我试图从列表视图控件中的标签检索文本。下面我使用的方法将只检索我想要的第一段文本。我正在寻找的文本是一个ID,因此无论我点击什么项目,我总是返回第一个ID。

Private Sub guidelinesList_SelectedIndexChanged(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles guidelinesList.SelectedIndexChanged
    i = guidelinesList.SelectedIndex
End Sub
Private Sub guidelinesList_ItemDataCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles guidelinesList.ItemCommand
    Dim theIdLabel As Label = CType(guidelinesList.Items(i).FindControl("lblId"), Label)
    guidelinesId = CInt(theIdLabel.Text)
    If String.Equals(e.CommandName, "bEdit") Then
        Response.Redirect("../EditFile.aspx?FileId=" & guidelinesId & "&FileType=Guidelines" & "&AppType=Payroll")
    End If
End Sub

需要的只是小的代码更改,见下文。

Private Sub guidelinesList_ItemDataCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles guidelinesList.ItemCommand
    If String.Equals(e.CommandName, "bEdit") Then
        Dim i As Integer = CInt(e.Item.DataItemIndex)
        Dim theIdLabel As Label = CType(guidelinesList.Items(i).FindControl("lblId"), Label)
        guidelinesId = CInt(theIdLabel.Text)
        Response.Redirect("../EditFile.aspx?FileId=" & guidelinesId & "&FileType=Guidelines" & "&AppType=Payroll")
    End If
End Sub

相关内容

  • 没有找到相关文章

最新更新