0

UserControll で RadComboBox を使用しています。すべての都市を RadComboBox のチェック ボックスにバインドしたいと考えています。そのために、次のようにコードを記述しました。

ASPX の場合:-

<script type="text/javascript">
function getItemCheckBox(item) {
    debugger;
    //Get the 'div' representing the current RadComboBox Item.
    var itemDiv = item.get_element();

    //Get the collection of all 'input' elements in the 'div' (which are contained in the Item).
    var inputs = itemDiv.getElementsByTagName("input");

    for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++) {
        var input = inputs[inputIndex];

        //Check the type of the current 'input' element.
        if (input.type == "checkbox") {
            return input;
        }
    }

    return null;
}
function check() {
    debugger;
    alert("hello");
}
function getCities() {

    var combo = $find("<%= cmbCity.ClientID %>");
    var hdnAddressType = document.getElementById("<%= hfGeoLocation.ClientID %>");
    var items = combo.get_items();
    var selectedItemsTexts = "";
    var selectedItemsValues = "";
    var itemsCount = items.get_count();
    for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++) {
        var item = items.getItem(itemIndex);

        var checkbox = getItemCheckBox(item);

        //Check whether the Item's CheckBox) is checked.
        if (checkbox.checked) {
            selectedItemsTexts += item.get_text() + ", ";
            selectedItemsValues += item.get_value() + ",";
        }
    }

    hdnAddressType.value = selectedItemsValues;

    selectedItemsTexts = selectedItemsTexts.substring(0, selectedItemsTexts.length - 2);
    selectedItemsValues = selectedItemsValues.substring(0, selectedItemsValues.length - 2);

    //Set the text of the RadComboBox with the texts of the selected Items, separated by ','.
    combo.set_text(selectedItemsTexts);

    //Set the comboValue hidden field value with values of the selected Items, separated by ','.
    combo.set_value(selectedItemsValues);

    //Clear the selection that RadComboBox has made internally.
    if (selectedItemsValues == "") {
        combo.clearSelection();
    }
}
</script>

<div>
      <telerik:RadComboBox ID="cmbCity" runat="server" Height="200px" ExpandDirection="Up"
                    Width="130px">
                    <ItemTemplate>
                        <div id="chk">
                            <asp:CheckBox ID="chkCity" runat="server" onclick="getCities();" Text='<%#Eval("CityName")%>' />
                        </div>
                    </ItemTemplate>
     </telerik:RadComboBox>
     <asp:HiddenField ID="hfGeoLocation" runat="server" />
</div>

コードビハインドで。次のコード:-

protected void Page_Load(object sender, EventArgs e)
{
    List<usp_SelectCmbCityResult> lstCity = null;
    if (!Page.IsPostBack)
    {
        lstCity = new CityDomain().SelectCmbCity();
        cmbCity.DataSource = lstCity;
        cmbCity.DataValueField = "CityName";
        cmbCity.DataTextField = "CityName";
        cmbCity.DataBind();
        MenUs.Common.Common.BindRadioButtonList(ref rbtnOrientation, typeof(MenUs.Common.Enums.Orientation));
        MenUs.Common.Common.BindRadioButtonList(ref rbtnTargetGender, typeof(MenUs.Common.Enums.TargetGender));
        MenUs.Common.Common.BindRadioButtonList(ref rbtnTargetMarital, typeof(MenUs.Common.Enums.TargetMaritalStatus));
    }
}

クリック/チェックボックスを実行すると、Gettig エラーが発生します

Microsoft JScript ランタイム エラー: 'getCities' が定義されていません

何が問題なのか教えてください?? 前もって感謝します.....


問題が解決しました。実際に問題が MasterPage にあったため、このエラーが生成されました。サポートしてくれてありがとう....

4

1 に答える 1

0

埋め込まれたASPタグを使用するよりも、ブラウザが認識するようにJavascriptコードを表示する方が適切です。

これらのASPタグは文字列に変換する必要があります。問題はこれらの文字列の1つである可能性が高いと思います。cmbCity.ClientIDまたはの値はわかりませんがhfGeoLocation.ClientID、コードが壊れている可能性があります。引用符または改行が含まれている場合、Javascriptコードは無効になります。

ブラウザのソースの表示機能を使用して、コードがブラウザにどのように表示されるかを確認する必要があります。これにより、問題が何であるかがわかる可能性があります。

于 2011-07-25T12:16:20.710 に答える