0
XML传递一个LINQ到XML列表到asp.net gridview中的列?
<Parent Name="Jodi">
<Children Name="xxx" age="20">
<Children Name="zzz" age="21">
</Parent>
<Parent Name="John">
<Children Name="aaa" age="18">
<Children Name="bbb" age="17">
</Parent>
C#:
//Loading the xml file
var xmlDoc=Xdocument.Load(xmlpath);
//Querying the names of the parents from the above xml file.
var parentlist=(from p in xmlDoc.Descendants("Parent")
select p.Attribute("Name").value.ToString();
List<string> PList= new List<string>();
PList=parentList.ToList();
//passing to list to the gridview in asp.net web page:
gvParentsList.DataSource=PList;
gvParentsList.DataBind();
Asp.net:
<asp:GridView runat="server" ID="gvParentsList" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Parents Name">
<ItemTemplate>
<asp:Label ID="lblParent" runat="server" Text='<%#Bind(PList) %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我无法通过 “的plist” 值的列grdview.I能够查询t的名字他上面的代码,但我无法显示到gridview。
有些人可以指导我在哪里错过这里的捕获?
一个asp:标签不采取集合,因此您可以连接plist中并指定为文本的ASP属性:标签 – HatSoft 2012-07-26 20:02:28