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

SelectedValue is always empty

1 Answer 45 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
jason
Top achievements
Rank 1
jason asked on 13 Jul 2010, 04:57 PM
I am simply trying to read the selected value of an item that is selected in RadComboBox but I am unable to do so.  The SelectedValue value is always empty.  This is a pretty simple usage case so I don't understand why this should be difficult.  Does anyone know what is going on?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim cmd As New SqlCommand
    Dim con As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
 
    cmd.Connection = con
    con.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
 
    con.Open()
    cmd.CommandText = "select top 100 CustomerID, isnull(Title, '') as Title, FirstName, LastName, FirstName + LastName as FullName from saleslt.customer"
 
    da.SelectCommand = cmd
    da.Fill(ds)
 
    RadComboBox1.DataValueField = "CustomerID"
    RadComboBox1.DataTextField = "FullName"
 
    RadComboBox1.DataSource = ds
    RadComboBox1.DataBind()
End Sub
 
Protected Sub RadComboBox1_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged
    Dim s As String
 
    s = e.Value
    s = RadComboBox1.SelectedValue
 
End Sub


<
telerik:RadComboBox ID="RadComboBox1" runat="server" Width="420"
    AllowCustomText="True" MaxHeight="300px" Filter="Contains" AutoPostBack="True">
    <HeaderTemplate>
        <ul>
            <li class="col1">Title</li>
            <li class="col2">First Name</li>
            <li class="col3">Last Name</li>
        </ul>
    </HeaderTemplate>
    <ItemTemplate>
        <ul>
            <li class="col1"><%#DataBinder.Eval(Container.DataItem, "Title").ToString()%></li>
            <li class="col2"><%#DataBinder.Eval(Container.DataItem, "FirstName").ToString()%></li>
            <li class="col3"><%#DataBinder.Eval(Container.DataItem, "LastName").ToString()%></li>
        </ul>
    </ItemTemplate>
</telerik:RadComboBox>

1 Answer, 1 is accepted

Sort by
0
Helen
Telerik team
answered on 16 Jul 2010, 02:03 PM
Hi Jason,

Please bind the RadComboBox only on the first Page_Load() and not on every postback. Your code should look like the following:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If (Not Page.IsPostBack) Then
        ................
        RadComboBox1.DataValueField = "CustomerID"
        RadComboBox1.DataTextField = "FullName"
      
        RadComboBox1.DataSource = ds
        RadComboBox1.DataBind()
     
    End If
End Sub


Kind regards,
Helen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
jason
Top achievements
Rank 1
Answers by
Helen
Telerik team
Share this question
or