问题描述:

I have two dropdownlist for which I have bound data from database.

<tr>

<td>

<label for="ddlCountry">

Country</label>

</td>

<td>

<select id="ddlCountry" name="ddlCountry">

</select>

</td>

</tr>

<tr>

<td>

<label for="ddlCurency">

Currency</label>

</td>

<td>

<select id="ddlCurrency" name="ddlCurrency">

</select>

</td>

</tr>

i have bound data to these data using Jquery

For ddlCurrency:

var $html1 = '';

$html1 += '<option value="">---Select Currency---</option>';

if ($currencyList != null || $currencyList != '') {

$.each($currencyList, function (index, item) {

$html1 += '<option value=' + item.Currency + '>' + item.Currency + '</option>';

});

}

$('#ddlCurrency').append($html1);

For ddlCountry:

var $html = '';

$html += '<option value="">---Select Country---</option>';

if ($countryList != null || $countryList != '') {

var $i = 0;

$.each($countryList, function (index, item) {

$html += '<option value=' + $i + '>' + item.Country + '</option>';

$i++;

});

}

$('#ddlCountry').append($html);

Now the problem is that when I programatically try to select the dropdownlist item ,there is the problem. There is no problem with data binding. When i pass arguments to the value which in my case comes from grid(not asp.net gridview) only ddlCountry shows the item with passed argument but ddlCurrency shows ---Select Currency--- which is my first item in ddlCurrency meaning it does not select anything.

here is the code for selecting dropdown item by passing arguments.

$('select[id=ddlCountry] option:contains(' + argus[5] + ')').attr('selected', true);

$("#ddlCurrency option[value=" + argus[6] + "]").attr('selected', 'selected');

Only first one selects dropdownlist item with desired item and second one does not select anything but both args have values

now when i do this :

$("#ddlCurrency option[value=" + 'USD' + "]").attr('selected', 'selected');

it selects item in dropdownlist.

网友答案:

Place argus[6] in single quotes here (Attribute Equals selector):

$("#ddlCurrency option[value='" + argus[6] + "']")
相关阅读:
Top