Set Selected Value for DropdownList on Clientside using Javascript

Sometimes we need show the dropdownlist control with some selected value after some activity ( without server postback ) on the web page.
we can do that on clientside with the help of javascript.

function SetSelectedIndex(dropdownlist,sVal)
{
var a = document.getElementById(dropdownlist);

for(i=0;i<a.length;i++)
{
if(a.options[i].value == sVal)
{
a.selectedIndex = i;
}

}

}

Call the above function on your required event i.e. onclick,onblur etc… from code behind.

SetSelectedIndex(‘<%=ddldropdownlistName.ClientID %>’,”ValueToBeSelected”)

Advertisements

3 thoughts on “Set Selected Value for DropdownList on Clientside using Javascript”

  1. Hi Shweta,

    In your Gridview, place template Field:

    and then the Javascript on the same ASPX page:

    function CheckUnCheckAll(ck) {
    $(‘#’).find(“input:checkbox”).each(function () {
    if (this != ck) {
    this.checked = ck.checked;
    }
    });
    }

    I Hope this is what you wanted to know.

    Kind regards,
    Pierre D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s