We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How do I set the dropdownlist selected value on the server page laod event?

Hi, I'm using the asp.net DropDownList control bound to a sql data source

<ej:DropDownList ID="DropDownList" runat="server" DataSourceID="sqlGroups" DataTextField="fldGroup" DataValueField="fldGroup">

</ej:DropDownList>

On the server page load event I want to find a value in the dropdownlist and select it.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then

   Dim strGroup As New Syncfusion.JavaScript.Web.DropDownListItem


   strGroup.Text = "test text"

   strGroup.Value = "test value"

  DropDownList.SelectedItemIndex = DropDownList.Items.FindIndex(strGroup)



End If

End Sub

I guess it will be something like this


3 Replies

ES Ezhil S Syncfusion Team July 27, 2015 04:45 PM UTC

Hi David,

Sorry about the inconvenience caused.

Currently it is not possible to access Items from code behind when data bound with DataSource in DropDownList control. We have internally logged this issue, and fix will be included in our upcoming SP1 release which is planned to roll-out in the end of July , 2015

Please let us know if you have any queries.


Regards,

Ezhil S



OD Oscar Daniel Vega Castaneda September 27, 2016 03:39 PM UTC

Ezhil S

Hi, this issues was solved?, I'm using Syncfusion 2016 Vol 1 (14.1.0.41) and I can't set value to dropdownlist. How I can do that?




KC Kasithangam C Syncfusion Team September 28, 2016 10:39 AM UTC

Hi David, 
 
Yes, the reported issue has been fixed in 2016 Vol 1 (14.1.0.41). We have a property called “value” which is used to specify the value for DropDownList control. Please find the code for same: 
 
<code> 
 
  protected void Page_Load(object sender, EventArgs e) 
        { 
            DrpDwnsql.Value = "Waterways"; 
        } 
 
 
<code> 
 
We have prepared the sample based on your requirement and it is available under the following link: 
 
Sample: Sample 
 
Regards, 
Kasithangam 


Loader.
Live Chat Icon For mobile
Up arrow icon