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

nothing return in selectIndexChange event

1 Answer 49 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 24 May 2014, 05:10 AM
hi

I am getting value Prod_ID return in the Page Load but nothing is return from selectedValue or radlistbox.SelectedItem.Value in the SelectedIndexChanged event even though autopostback is set to true. I have 5 records in the DB.

How should i resolve this?  Thanks a lot.

 <telerik:RadListBox ID="radlistbox" runat="server" Width="100%" EnableViewState="false" Skin="Metro" style="top: 0px; left: 0px" SelectionMode="Multiple" AutoPostBack="True">
</telerik:RadListBox>

 Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
       If Not Page.IsPostBack Then
            listboxdatabind()
            radlistbox.SelectedIndex = 0
            Dim a As String = radlistbox.SelectedItem.Value
        End If
    End Sub
 

 Sub listboxdatabind()
        radlistbox.DataSource = prodDatatable()
        radlistbox.DataTextField = "Prod_Name"
        radlistbox.DataValueField = "Prod_ID"
        radlistbox.DataBind()
    End Sub

Protected Sub radlistbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles radlistbox.SelectedIndexChanged
        listboxdatabind()
        Dim x As String = radlistbox.SelectedValue
        Dim y As String = radlistbox.SelectedItem.Value
 End Sub

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 May 2014, 08:43 AM
Hi,

In general the selected value will be persisted when the control is being bound to the data source only once. When binding is performed the previous selection is cleared since you might be filling different data and therefore it is not valid to keep selection for something which might not be in the current data set. In case the binding is performed in Page_Init event thus the selection will be persisted since the ViewState is not applied yet. Please try the following VB code snippet which works fine at my end.

VB:
Protected Sub Page_Init(sender As Object, e As EventArgs)
    listboxdatabind()
End Sub
Protected Sub radlistbox_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim x As String = radlistbox.SelectedItem.Value
End Sub

Thanks,
Shinu.
Tags
ListBox
Asked by
L
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or