Simon Simon -4 years ago 267
ASP.NET (C#) Question dropdown list always select 0 index with postback

working on a simple project after click a button i'm clear all textbox text and I want dropdown list select it's 0 index value..........I'm trying to write some jquery code to complete this work

$(document).ready(function () {
$("#btnAdd").bind("click", function () {
$("#productNameDDL")[0].selectedIndex = 0;

but don't work this code what should have I do now.Thanks in advanced

Answer Source

Since you tagged your question with, the problem is most likely the id of the DropDownList. Use:

$("#<%= productNameDDL.ClientID %>").prop('selectedIndex', 0); renames the ID propery of a Control on the client side to ensure unqiue id's. See the Microsoft Site for more info.


To change the SelectedIndex of a DropDownList programatically you can use this.

protected void Button1_Click(object sender, EventArgs e)
    productNameDDL.SelectedIndex = 0;
    productNameDDL.SelectedValue = "value";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download