locked
How to retrieve the datakeynames from a listview? RRS feed

  • Question

  • User709523361 posted

    Hi
    I need to retrieve the datakeynames from a line of a listview hitting a button.
    I'm using VB.net in a webform.

    Thanks in advance

    Fiore

    Friday, May 13, 2016 4:42 PM

Answers

  • User2103319870 posted

    I need to retrieve the datakeynames from a line of a listview hitting a button.
    I'm using VB.net in a webform.

    If you have a click event attached to the button then you can use the below code to get the datakey value of current selected item

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            'Get the selected listview item
            Dim item As ListViewItem = TryCast(TryCast(sender, Button).NamingContainer, ListViewItem)
            'Get the datakey from listview
            'Change the listview id and datakey name here
            Dim idvalue As Integer = CInt(ListView1.DataKeys(item.DataItemIndex).Values("YourDataKeyName"))
        End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 13, 2016 4:57 PM

All replies

  • User2103319870 posted

    I need to retrieve the datakeynames from a line of a listview hitting a button.
    I'm using VB.net in a webform.

    If you have a click event attached to the button then you can use the below code to get the datakey value of current selected item

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            'Get the selected listview item
            Dim item As ListViewItem = TryCast(TryCast(sender, Button).NamingContainer, ListViewItem)
            'Get the datakey from listview
            'Change the listview id and datakey name here
            Dim idvalue As Integer = CInt(ListView1.DataKeys(item.DataItemIndex).Values("YourDataKeyName"))
        End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 13, 2016 4:57 PM
  • User36583972 posted

    Hi fiore,

    The following tutorial for your reference, It details the use of datakeynames.

    Asp.Net VB – Listview – ItemCommand – DataKeys – CommandName – SQL:

    http://dan.folkes.me/2011/08/01/asp-net-vb-listview-itemcommand-datakeys-commandname-sql/

    Best Regards,

    Yohann Lu

    Monday, May 16, 2016 6:09 AM