This is a migrated thread and some comments may be shown as answers.

Get ListBoxItem data value from code behind

1 Answer 107 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 31 Mar 2016, 12:33 AM

 

Hi - I need to get the data value of the item that has been transferred using code behind. Please could you give me an example. Thank you.

  

Protected Sub RadListBox2_Inserted(ByVal sender As Object, ByVal e As RadListBoxEventArgs)
       .....code to get the data value of the item that was transferred......
 
  End Sub

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 04 Apr 2016, 02:20 PM
Hello Max,

In order to get the data from the item/items transferred in the code-behind, you have to set the source ListBox' AutoPostBackOnTransfer property to true and in the control's OnTransferred server-side event handler you can access the collection (e.Items) of transferred items and each item in it by index:
Protected Sub RadListBox1_Transferred(sender As Object, e As Telerik.Web.UI.RadListBoxTransferredEventArgs)
    Label1.Text += "Items with Text/Value transferred: "
    For i As Integer = 0 To e.Items.Count - 1
        Label1.Text += "[" + e.Items(i).Text + "/" + e.Items(i).Value + "]"
    Next
End Sub

The code snippet above gets the transferred items' Text and Value property values and updates a Label's Text with the data.

Regards,
Ivan Danchev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
ListBox
Asked by
Max
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or