如何将数据集数据绑定到 web 服务的下拉列表
How to bind datasets data to dropdownlist from webservices
我在从 http://www.webservicex.net/country.asmx/GetCountries however, my dropdownlist shows data in char format https://imgur.com/a/P6Ahn 填充 DropDownList1 中的数据集时遇到问题,我不确定为什么。
country count = new country(); //from Service
DropDownList1.DataSource = count.GetCountries();
DropDownList1.DataBind();
似乎您的 asmx 服务正在提供 xml 而您正试图直接将其与下拉列表绑定,这是不正确的。
您需要将 xml 转换为数据集,然后尝试绑定。
string xmlFile = count.GetCountries();
DataSet dataSet = new DataSet();
dataSet.ReadXml(xmlFile, XmlReadMode.InferSchema);
DropDownList1.DataSource = dataSet OR dataSet.Tables[0];
DropDownList1.DataTextField = "Name";
DropDownList1.DataBind();
我在从 http://www.webservicex.net/country.asmx/GetCountries however, my dropdownlist shows data in char format https://imgur.com/a/P6Ahn 填充 DropDownList1 中的数据集时遇到问题,我不确定为什么。
country count = new country(); //from Service
DropDownList1.DataSource = count.GetCountries();
DropDownList1.DataBind();
似乎您的 asmx 服务正在提供 xml 而您正试图直接将其与下拉列表绑定,这是不正确的。
您需要将 xml 转换为数据集,然后尝试绑定。
string xmlFile = count.GetCountries();
DataSet dataSet = new DataSet();
dataSet.ReadXml(xmlFile, XmlReadMode.InferSchema);
DropDownList1.DataSource = dataSet OR dataSet.Tables[0];
DropDownList1.DataTextField = "Name";
DropDownList1.DataBind();