ASP.NET C# Filter DropDownList based on specific Category of Items from Soap Service

╄→尐↘猪︶ㄣ 提交于 2019-12-11 04:59:18

问题


OK... I'm stuck here. Sort of new to C# and consuming web services. I have successfully populated a DropDownList from a SOAP service, but what I really need is to filter that list based on a specific category.

Here's what I have so far:

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 contains "category", "description" and "code". How do I set the DataSource to equal getDescList where category = Category1? (There's 4 categories of items. The category will be set by a user selecting a category from the previous page, and that value being pulled from the URL via HttpUtility.UrlDecode.)

Thank you in advance for your assistance.


回答1:


Is there a reason why you do not do this on your SQL (if you are using SQL at all). If you can't I would suggest that you take a look at LinQ2Entities. Good luck!




回答2:


Try this, you could filter after the call with Linq, but I recommend you change your web service to take a param to filter the results:

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();


来源:https://stackoverflow.com/questions/8300414/asp-net-c-sharp-filter-dropdownlist-based-on-specific-category-of-items-from-soa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!