无法将XML文件绑定到asp.net中的下拉列表
我对asp.net很陌生 我下载了这个xll文件,它是这样的无法将XML文件绑定到asp.net中的下拉列表,asp.net,xml,Asp.net,Xml,我对asp.net很陌生 我下载了这个xll文件,它是这样的 <?xml version="1.0" encoding="utf-8"?> <countries author="Banmeet Singh" title="Country, State-Province selections" date="2008-Feb-05"> <country name="Afghanistan"> <state>Badakhshan<
<?xml version="1.0" encoding="utf-8"?>
<countries author="Banmeet Singh" title="Country, State-Province selections"
date="2008-Feb-05">
<country name="Afghanistan">
<state>Badakhshan</state>
<state>Badghis</state>
<state>Baghlan</state>
<state>Balkh</state>
<state>Bamian</state>
<state>Farah</state>
<state>Faryab</state>
<state>Ghazni</state>
<state>Ghowr</state>
<state>Helmand</state>
<state>Herat</state>
<state>Jowzjan</state>
<state>Kabol</state>
<state>Kandahar</state>
Ir给出了这个错误
:-数据绑定:“System.Data.DataRowView”不包含名为“state”的属性。
请告诉我我做错了什么。谢谢
好的,这里是html代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</form>
</body>
</html>
您必须将列表绑定到
数据集中的表
因此,您的绑定应该更像这样(假设数据集中只有一个表)
也可以尝试绑定到列,如下所示:
DropDownList1.DataTextField = ds.Tables[0].Columns["country"].ToString();
最后,您不需要绑定()两次,只需一次。设置完所有属性后,通常是一个好地方
关于你的状态
错误-你确定你发布了所有涉及的代码吗?只有当您试图访问“状态”并且看起来您不是来自您发布的内容时,才会出现这种情况。请向我们展示DropDownList的html部分1
DropDownList1.DataSource = myDataSet.Tables[0];
DropDownList1.DataTextField = ds.Tables[0].Columns["country"].ToString();