简体   繁体   English

其他过滤器上的过滤器下拉列表

[英]Filter dropdown list on other filter

Hey guys I know it had been discussed so much but I still don't get it working. 嗨,我知道讨论了很多,但我仍然没有解决。

What I need is to filter a gridview by a few dropdown lists and the main idea is to "continue" filtering the gridview. 我需要的是通过几个下拉列表过滤GridView,主要思想是“继续”过滤GridView。 I mean, when I select value from ddl1, then the ddl2 is filtered according to the selected value in ddl1. 我的意思是,当我从ddl1中选择值时,ddl2会根据ddl1中的选定值进行过滤。

Also called cascading dropdown list but I don't want to (can not) use Ajax Control Toolkit... 也称为级联下拉列表,但我不想(不能)使用Ajax Control Toolkit ...

Any other solutions to that? 还有其他解决方案吗? Maybe the method protected void DropDownList2_SelectedIndexChanged(...) can do this but I don't know how to use it. 也许protected void DropDownList2_SelectedIndexChanged(...)的方法protected void DropDownList2_SelectedIndexChanged(...)可以做到这一点,但我不知道如何使用它。

Please help Thanks in advance. 请提前帮助。

Have a look at the below. 看看下面。 It is just to give you an idea... 只是给你一个主意...

DropDownList1_SelectedIndexChanged(...){
// get the ddl1 selected value
// filter the datasource used by dropdownlist2
// databind DropDownList2 
}

DropDownList2_SelectedIndexChanged(...){
    // get the ddl1 selected value 
    // get the ddl2 selected value 
    // filter the datasource used by GridView(using the DropDownList selected values)
    // databind GridView 
}

I would suggest to use Jquery to fill cascaded dropdownlists. 我建议使用Jquery来填充级联的dropdownlists。 Add this script to your webpage. 将此脚本添加到您的网页。

$(document).ready(function () {

$("#<%= ddlState.ClientID %>").change(function () { $(“#<%= ddlState.ClientID%>”)。change(function(){

var sourceddl = "<%= ddlState.ClientID %>";
var stateid = $("#<%= ddlState.ClientID %> option:selected").val();
var Stateid = { Stateid: stateid };

$.ajax({
                type: 'POST',
                url: 'YourCodeBehind.aspx/GetCounties',
                data: JSON.stringify(Stateid),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {                       
                          if (data.d) { 
                          var options = [];                     
                          if (result.d) {
                          for (var i = 0; i < result.d.length; i++) {
                               options.push('<option value="',
                                              result.d[i].countyID, '">',
                                              result.d[i].countyName, '</option>');
                            }

                            $("#<%= ddlCounty.ClientID %>").html(options.join(''));
                        }                        
                     }
                },
                error: function () {
                    alert("Error! Try again...");
                }
            });

        });

    });

here is the webmethod which is in the same codebehind. 这是隐藏在同一代码中的网络方法。

[WebMethod]
public static County[] GetCounties(int Stateid)
{
    County[] countiesArr = StatesCountyModel.GetCountyForState(Stateid).ToArray();
    return countiesArr;     
}

If you are new to Jquery. 如果您不熟悉Jquery。 go through the http://Jquery.com to understand how to use it. 请访问http://Jquery.com了解如何使用它。

Hope it helps. 希望能帮助到你。

Praveen 普利文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM