【问题标题】:Telerik Dropdown list not displaying first value after ajax refreshTelerik 下拉列表在 ajax 刷新后不显示第一个值
【发布时间】:2011-05-13 19:15:40
【问题描述】:

我正在实现两个下拉列表,其中“基金”下拉列表通过选择“关闭日期”下拉列表(级联)来填充。问题是在 Ajax 更新后,“基金”下拉列表显示一个空白值,而不是第一个选择。我验证了返回的选项将第一个项目标记为“已选择”。我还尝试了一些方法来默认更新后下拉列表的选定索引。那么,如何在更新后将下拉菜单默认为特定的选择。下面列出了定义下拉列表和选择“关闭日期”时运行的 javascript 函数的代码片段。

使用 Telerik 2011.1.315 和 JQuery 1.5.1

<script type="text/javascript">
    fundListUrl = '<%= Url.Action("GetFundList","Admin") %>'
    function GetFundList(e)
    {
        var fundDropDown = $('#FundId');
        var fundDropDownData = fundDropDown.data('tDropDownList');
        fundDropDownData.loader.showBusy();
        $.get(fundListUrl, { dateId: e.value }, function (data) {
            fundDropDownData.dataBind(data);
            fundDropDownData.loader.hideBusy();
            fundDropDown.attr('selectedIndex', 0); // Not Working
        });
    }
</script>

...

<table>
    <tr>
    <td class="editlabel">Close Date:</td>
    <td>
        <%= Html.Telerik().DropDownListFor(o => o.ReportingPeriodDateId)
            .BindTo((SelectList)ViewData["closeDateList"])
            .ClientEvents(events => events.OnChange("GetFundList"))
        %>
    </td>
    </tr>
    <tr>
    <td class="editlabel">Fund:</td>
    <td>
        <%= Html.Telerik().DropDownListFor(o=>o.FundId)
            .BindTo((SelectList)ViewData["fundList"])
            .HtmlAttributes(new { style = "width: 40em;" })
        %>
    </td>
    </tr>
</table>

【问题讨论】:

    标签: jquery asp.net-mvc jquery-ui telerik telerik-mvc


    【解决方案1】:

    您应该能够通过其索引或其值(如果您事先为组合框项定义值)选择一个组合项,如下所示:

    <script type="text/javascript">
        fundListUrl = '<%= Url.Action("GetFundList","Admin") %>'
        function GetFundList(e)
        {
            var fundDropDown = $('#FundId');
            var fundDropDownData = fundDropDown.data('tDropDownList');
            fundDropDownData.loader.showBusy();
            $.get(fundListUrl, { dateId: e.value }, function (data) {
                fundDropDownData.dataBind(data);
                fundDropDownData.loader.hideBusy();
                fundDropDown.select(0); // select first combo item, or use fundDropDown.value('0') in case the first combo item has value set to 0
            });
        }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多