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

Can't set SelectValue in databound dropdownlist

1 Answer 136 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 10 Nov 2017, 07:02 PM

What I'm trying is so simple, but doesn't work

-----------------------------

Imports Telerik.WinControls.UI

Public Class frmListTest
  Private dtTest As DataTable   

    Private Sub frmListTest_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            fillDataTable(dtTest)  ' procedure fills the table from an Oracle database procedure

            myDropDownList.DataSource = dtTest

            myDropDownList.ValueMember = "VALUE_MEMBER"
            myDropDownList.DisplayMember = "DISPLAY_MEMBER"

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        myDropDownList.SelectedValue = 6  '  DOES NOT WORK
    End Sub

-------------------------------------

dtTemp structure
value_member     display_member
24                         Athletic Operations Building
1                           Camp Randall Stadium
34                         Camp Randall Stadium Misc.
22                         Cr Sports Center [shell] - Womens Hockey
37                         Goodman Diamond All Season Practice
6                           Goodman Softball Complex
23                         Kellner Hall 
2                           Kohl Center
35                         La Bahn Arena
4                           McClain Center

The dropdown list loads ok, but I can't select an item through the SelectedValue property.

What am I doing wrong, or not doing? 

Telerik V 2016.3.913.40

Visual Studio Pro V 14.0.25431.01

 

Later

Art


1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Nov 2017, 09:34 AM
Hi Art,

This works fine on my side (see attached project). 

What can cause such issue is when you are storing the numbers as a string for example. So make sure that you are using the correct data type when setting the SelectedValue.

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Greg
Top achievements
Rank 1
commented on 07 Jun 2023, 06:56 AM

I'm experiencing the very same issue, however, I'm using an integer value for the valuemember field and a text field for the display member field ... exmple code blow ... and I'm UNABLE to set the selectedValue of ANY dropdown list I'm using in my project. Seriously frustrating and not sure why it doesn't work.

code:

           Dim strSQL As String = "Select
                                        Opportunity_Flags.ID,
                                        Opportunity_Flags.FlagText
                                    From
                                        Opportunity_Flags"


            SQL.ExecQuery(strSQL, "DBDT")

            If SQL.RecordCountDBDT > 0 Then
                With DropDown
                    .ValueMember = "ID"
                    .DisplayMember = "FlagText"
                    .DataSource = SQL.DBDT
                    .SelectedValue = 2
                End With
            End If
Dinko | Tech Support Engineer
Telerik team
commented on 07 Jun 2023, 09:26 AM

We have already replied to your question, in the other ticket thread created from your account. Let's continue there. I am copying the answer also here:

In general, the SelectedValue property needs to match the type of object which is shown in the dropdown content of the controls. For example, if the ID is a numeric value, the SelectedValue will need to be set to a numeric value, if it is a string, the SelectedValue needs to be set to a string value. I have tested your approach and it is working as expected. The SelectedValue property set the correct value. Can you check the attached project and let me know what is the difference between my data and yours?

Tags
DropDownList
Asked by
Art
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or