2011-05-13 42 views
0

我正在实施两个下拉列表,其中“基金”下拉列表由选择“关闭日期”下拉列表(级联)填充。问题在于,在Ajax更新之后,“Fund”下拉列表显示空白值而不是第一个选择。我确认了返回的选择有第一项标记为“已选中”。我还尝试了几件事情来更新后默认选择下拉列表的索引。那么如何将下拉菜单默认更新为特定选项。以下是用于定义下拉列表的代码片段以及在选择“关闭日期”时运行的JavaScript函数。Telerik下拉列表在Ajax刷新后不显示第一个值

使用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> 

回答

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> 
相关问题