0

コードビハインドでドロップダウンリストの選択された値を取得する方法は?

私のaspxページにはドロップダウンリストがあります

Jqueryを使用して、アイテムを追加しています

var city = $("#city").val();
if (city.toString() != "") {
    var citySelect = $('#cityName');
    citySelect.append($('<option></option>').val('0').html('-Select City-'));
    for (i = 0; i < City.response_list.length; i++) {
        citySelect.append($('<option></option>').val(City.response_list[i].id_city + " - " + City.response_list[i].label).html(City.response_list[i].id_city + " - " + City.response_list[i].label));
    }
}

選択した値を取得しようとすると、分離コードで「System.NullReferenceException: オブジェクト参照がオブジェクトのインスタンスに設定されていません」というメッセージが表示されます。

選択した値を取得するには?

4

1 に答える 1

0

Your Select input which you add some options with JQuery to it, it is a Client side object and in no circumstances you can have access to it using code behind

To access this object you have to add to property to your select input

ID and runat=server thsese to property let you access your object from the code behind, you final select should be something like this

<select id="select1" runat="server">
    <option value="val1">dfgbfbff</option>
</select>

then in your code behind you can check its values with checking the select1

于 2013-07-16T05:55:07.297 に答える