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

Can't select item

1 Answer 227 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Web Services
Top achievements
Rank 2
Web Services asked on 16 Aug 2011, 10:25 PM
I have a rad combo box that I bind in my code with a data table. Whenever I select an item and then click out of the combo box, it doesn't keep the item I had picked selected. You can see my problem here http://michael.sprayapplications.com/temp.aspx . Just pick an item and then click out of the dropdown. Here is my aspx code

<telerik:RadComboBox ID="salesInput" runat="server" Width="200px" MarkFirstMatch="true">
</telerik:RadComboBox>

here's my vb code behind and the function it calls
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        If (Not Page.IsPostBack) Then
            'populate the dropdown
            Dim tableOfData As DataTable = MyFunctions.createCrewDeleteTable()
            salesInput.DataSource = tableOfData
            salesInput.DataTextField = "Salesman"
            salesInput.DataValueField = "CrewId"
 
            salesInput.DataBind()
        End If
End Sub

And the function
    'this function gets the data for the crew dropdown
    'this sub returns a data table to bind to the dropdown
    Public Shared Function createCrewDeleteTable()
 
        'a new data table
        Dim table As DataTable = New DataTable()
        table.Columns.Add("Salesman")
        table.Columns.Add("CrewId")
 
        Dim type
 
        'my sql connection
        Dim myConn As New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("connection").ToString)
 
        'the name of the stored procedure
        Dim strSQL = "select FirstName+' '+LastName as Name, CrewType, CrewId from Crew where Deleted <> 'yes' " & _
        "AND crewid > 1 order by LastName, Firstname"
 
        Try
 
            myConn.Open()
            Dim readCommand As New Data.SqlClient.SqlCommand(strSQL, myConn)
 
            'while we have rows from the stored procedure
            'we will add them to a data table
            Dim cdr As SqlDataReader = readCommand.ExecuteReader()
            While cdr.Read()
 
                If (cdr(1).ToString = "3") Then
                    type = "Salesman"
                ElseIf cdr(1).ToString = "2" Then
                    type = "Crew Chief"
                Else
                    type = "Crew"
                End If 'if cdr(2)
 
                If (cdr.Item(0).ToString <> "") Then
 
                    table.Rows.Add(New String() {cdr.Item(0) & " - " & type, cdr.Item(1)})
 
                End If
 
            End While 'while cdr.Read()
 
        Catch ex As Exception
 
        End Try
        myConn.Dispose()
 
        Return table
 
End Function



1 Answer, 1 is accepted

Sort by
0
Cat Cheshire
Top achievements
Rank 1
answered on 17 Aug 2011, 10:01 AM
This issue can occur when there are items with same values in combobox - please take a look at this article.
Tags
ComboBox
Asked by
Web Services
Top achievements
Rank 2
Answers by
Cat Cheshire
Top achievements
Rank 1
Share this question
or