如何使用C#从网站获取数据并在Combobox中填充? [英] How to fetch data from a website using C# and populate it in Combobox?
本文介绍了如何使用C#从网站获取数据并在Combobox中填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用C#表格的桌面应用程序。我需要在组合框中使用这个列表列表作为下拉列表,就像这个。
我填充了组合框下拉列表我。但我想从给定的链接中获取该列表。我在google上搜索并找到了一些答案,但他们没有帮助。
我试图获取该数据通过使用以下代码,但我只得到一些类似html的内容。
I'm working on a desktop application in C# forms.I need this List of Banks in a combobox as drop down list, like this one.
I've populated the combobox drop down list myself. But I want to fetch that list from the given link.I've search on google and found few answers but they are not helping.
I tried to get that data by using following code but I only got some html like contents in result.
System.Net.WebClient wc = new System.Net.WebClient();
string webData = wc.DownloadString("http://www.pakwatan.pk/banks-pakistan/");
cbBankName.DataSource = webData.ToList();
我不知道如何从webdata中的结果中提取需求内容。
有人请帮忙。
I don't know how to extract require contents from result in webdata.
someone please help.
推荐答案
尝试HtmlAgilityPack库(从 https://htmlagilitypack.codeplex.com 下载[< a href =https://htmlagilitypack.codeplex.comtarget =_ blanktitle =New Window> ^ ]或作为NuGet包来解析HTML并提取所需的列表。但由于这不是Web服务,因此很容易出错。即使标记中的微小变化也会破坏您的代码,因此它不会非常可靠。
Try HtmlAgilityPack library (download from https://htmlagilitypack.codeplex.com[^] or as a NuGet package) to parse the HTML and extract the list you need. But since this is not a web service it will be very prone to error. Even small changes in the markup can break your code so it wouldn't be very reliable.
这篇关于如何使用C#从网站获取数据并在Combobox中填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文