nothing return in selectIndexChange event

2 posts, 0 answers
  1. L
    L avatar
    295 posts
    Member since:
    Apr 2008

    Posted 24 May 2014 Link to this post


    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">

     Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
           If Not Page.IsPostBack Then
                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"
        End Sub

    Protected Sub radlistbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles radlistbox.SelectedIndexChanged
            Dim x As String = radlistbox.SelectedValue
            Dim y As String = radlistbox.SelectedItem.Value
     End Sub
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 May 2014 in reply to L Link to this post


    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.

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

  3. DevCraft R3 2016 release webinar banner
Back to Top