【问题标题】:Cascading DropDownList GridView ObjectDataSource级联 DropDownList GridView ObjectDataSource
【发布时间】:2012-01-13 03:58:32
【问题描述】:

我的页面包含使用纯 ajax 的级联 DDL 和网格视图。 GridView 从 sqlDataSouce 获取数据,它应用将 DDL 的值作为参数的存储过程。 当我在 DDL 中选择值时,网格视图会更改其数据而不刷新整个页面。

昨天我不得不更改存储过程,由于某种原因,sqlDataSource 开始出现获取数据的问题。

所以经过多次尝试使其工作后,我终于尝试使用 ObjectDataSource,它设法正确运行存储过程并获取数据。但是现在当我在 DDL 中选择值时,我得到了页面错误并且 GridView 保持原样。

我可以让谁工作? (搜索时没有找到满意的答案) 非常感谢:-)

【问题讨论】:

    标签: ajax gridview objectdatasource cascadingdropdown


    【解决方案1】:
     cascading Country and state DDL
        @Html.DropDownListFor(model => model.CountryId, Model.CountryList, "--Select Country--", new { @class = "CountryList", style = "width:150px" })
    
         @Html.DropDownListFor(model => model.StateId, Model.StateList, "--Select State--", new { @class = "StateList", style = "width:150px" })
    
        <script type="text/javascript">
            $(document).ready(function () {
                $.post("/Client/GetModels", { id: $(".CountryList").val() }, function (data) {
                    populateDropdown($(".StateList"), data);
                });
                $(".CountryList").change(function () {
                    $.post("/Client/GetModels", { id: $(this).val() }, function (data) {
                        populateDropdown($(".StateList"), data);
                    });
                });
            });
    
            function populateDropdown(select, data) {
                $(".StateList").empty();
                $.each(data, function (id, option) {
                    $(".StateList").append("<option value='" + option.StateId + "'>" + option.State + "</option>");
                });
            }
        </script>
    

    【讨论】:

      猜你喜欢
      • 2011-04-23
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      相关资源
      最近更新 更多