ASP.NET C#基于Soap服务中特定项目类别的筛选下拉列表

ASP.NET C#基于Soap服务中特定项目类别的筛选下拉列表,c#,asp.net,c#-4.0,drop-down-menu,soap-client,C#,Asp.net,C# 4.0,Drop Down Menu,Soap Client,好的。。。我被困在这里了。对于C#和消费web服务来说是一种新的体验。我已经成功地从一个SOAP服务填充了一个DropDownList,但我真正需要的是根据特定的类别过滤该列表 以下是我目前掌握的情况: problemReporting.soapClient s = new problemReporting.soapClient(); problemReporting.NullRequest nr = new NullRequest(); problemReporting.ProblemDesc

好的。。。我被困在这里了。对于C#和消费web服务来说是一种新的体验。我已经成功地从一个SOAP服务填充了一个DropDownList,但我真正需要的是根据特定的类别过滤该列表

以下是我目前掌握的情况:

problemReporting.soapClient s = new problemReporting.soapClient();
problemReporting.NullRequest nr = new NullRequest();
problemReporting.ProblemDescription[] getDescList = s.getProblemDescriptionList(nr);

ddlProblem.DataSource = getDescList;
ddlProblem.DataTextField = "description";
ddlProblem.DataValueField = "code";
ddlProblem.DataBind();
problemReporting.ProblemDescription包含“类别”、“说明”和“代码”。如何将数据源设置为等于getDescList,其中category=Category1?(共有4个项目类别。该类别将由用户从上一页中选择一个类别来设置,该值将通过HttpUtility.UrlDecode从URL中提取。)


提前感谢您的帮助。

尝试此操作,您可以在通话后使用
Linq
进行筛选,但我建议您更改web服务以使用参数筛选结果:

problemReporting.soapClient s = new problemReporting.soapClient();
problemReporting.NullRequest nr = new NullRequest();
problemReporting.ProblemDescription[] getDescList = s.getProblemDescriptionList(nr);

var cats = from desc in getDescList 
  where desc.category == "Category1"
  select desc;

ddlProblem.DataSource = cats;
ddlProblem.DataTextField = "description";
ddlProblem.DataValueField = "code";
ddlProblem.DataBind();

您不在SQL上这样做有什么原因吗(如果您使用的是SQL的话)。如果你不能,我建议你看看。祝你好运

如果我理解正确的话。数据源将被分配给您的集合/数组,不管它包含什么。您需要从OnChange事件下拉列表中使用新类别再次调用s.getProblemDescriptionList()。然后下拉.DataBind()使其生效。谢谢您的回复。我添加了更多关于如何设置类别的信息。我希望这有助于澄清问题。你的建议是正确的。您可以重新设计并使用两种web服务方法。1将获取您的所有类别,另一个将获取该类别的所有项目。因此,在启动/init/onload/etc时,您可以调用wsclient.GetCategories(),然后调用wsclient.GetItemsForCategory(“Categori1”),我唯一的数据源是soap服务。我查看了“LINQ到实体查询示例”。成功了。感谢Hanlet。不得不将其稍微调整为:var catList=来自getDescList中的desc,其中desc.category==“Category1”选择desc;但它起了作用。谢谢你,瑞克。