Here is the code i am uisng to get the xl file into the Grdview:
protected void Page_Load(object sender, EventArgs e)
{
string filePath = Server.MapPath("App_Data/IRLFacility.xml");
DataSet ds = new DataSet();
//Read the contents of the XML file into the DataSet
ds.ReadXml(filePath);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
This is the code on the aspx page for the grid view:
Floor_Text
First Foor
Second Floor
Third Floor
Fourth Floor
But it should look more like this:
First Floor Pharmacy
Radiology
Pathology
CHAMPS
Audiology
Second Floor Ophthalmology
General Pediatrics
Otolaryngology
Third Floor
and so on
In fact I think you can use XmlDocument or LINQ-TO-XML and do a "nested" databinding。Something looks like this following:
【Solutions】
var result = from e in XDocument.Load("xxx.xml").Descedants("Floor")
select new
{
FloorName = e.Value,
DepartNames = from f in e.Descedants("Department")
select f.Value
}
And then your GridView should be something like this:
Thanks Decker... I used your code and your gridview and got nothing to display so I am still looking for a complete answer if anyone is willing. Thanks in advance
Here is he code and the grid view that didnt work.
protected void Page_Load(object sender, EventArgs e)
{
string filePath = Server.MapPath("App_Data/test.xml");
var result = from f in XDocument.Load(filePath).Descendants("Floor")
select new
{
FloorName = f.Value,
DepartNames = from g in f.Descendants("Department")
select g.Value
};
}
<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="false" Enabled="true"
Visible="true" OnLoad="gvload">
<Columns>
<asp:TemplateField HeaderText="FloorName">
<ItemTemplate><%#Eval("FloorName")%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Departments">
<ItemTemplate><%#Eval("Department")%></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You should know that "Departments" is another collection nested in the collection of result,So plz nest another GridView inside the ItemTemplate of the outer GridView,and then do databinding:-)
No matter how you slice it Dong, this does not work as you have described it. if I am missing something then "I dont know what it is" or I wouldnt be here asking for help. So before you continue with trying to degrade me for asking for a little help, maybe
you should try giving a complete and detailed answer that doesnt assume we know what you are talking about.
This is my code and it currently does NOT work. PLease help with a complete answer.
asp.net
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
Enabled="true" Visible="true" GridLines="None"
HorizontalAlign="Center" Width="100%" CellPadding="5" CellSpacing="1">
<RowStyle Font-Size="X-Large" HorizontalAlign="Center" BackColor="#3E3E3D" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="Black" />
<HeaderStyle Font-Bold="True" Font-Size="XX-Large" BackColor="#D7AD3B" />
<Columns>
<asp:TemplateField HeaderText="Floor">
<ItemTemplate><%#Eval("Floor")%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department">
<ItemTemplate>
<div>
<asp:GridView id="GridView4" runat="server" AutoGenerateColumns="false"
DataSource='<%#Eval("DeptName")%>' >
<Columns>
<asp:TemplateField HeaderText="Department">
<ItemTemplate> <%#Eval("DeptName")%> </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
string filePath3 = Server.MapPath("App_Data/test.xml");
var result = from f in XDocument.Load(filePath3).Descendants("Floor")
select new
{
FloorName = f.Value,
DepartNames = from g in f.Descendants("DeptName")
select g.Value
};
}
Sorry but in the nested GridView's DataSource you should say "DepartNames" instead of "DeptName"……;Well,plz attention to my complete codes——
【cs code-behind】
protected void Page_Load(object sender, EventArgs e)
{
string filePath3 = Server.MapPath("App_Data/test.xml");
var result = from f in XDocument.Load(filePath3).Descendants("Floor")
select new
{
FloorName = f.Value,
DepartNames = from g in f.Descendants("DeptName")
select g.Value
};
}
Kindly correct me If I'm wrong,and if anything urgent,send your whole proj with xml file directly to v-dedong@microsoft.com,and I'll analyze it if I have free time……
how is this for kindly correcting you. I took you literally this time! and posted your code in exactly as you posted it! i even changed my XMLfile name to xxx.xml for you. Got the following errors as stated below below!! I am not sending you my project
when i have posted all the code here already.
Error 2 The "EntityClean" task could not be loaded from the assembly c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.Build.Tasks.dll. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT:
0x80131040) Confirm that the <UsingTask> declaration is correct, and that the assembly and all its dependencies are available. IRLBigBoard
Error 3 'System.Xml.Linq.XDocument' does not contain a definition for 'Descedants' and no extension method 'Descedants' accepting a first argument of type 'System.Xml.Linq.XDocument' could be found (are you missing a using directive or an assembly reference?) C:\mypath\Default.aspx.cs 49 62 IRLBigBoard
Error 4 The range variable 'e' conflicts with a previous declaration of 'e' C:\mypath\Default.aspx.cs 49 31 IRLBigBoard
Error 2 The "EntityClean" task could not be loaded from the assembly c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.Build.Tasks.dll. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT:
0x80131040) Confirm that the <UsingTask> declaration is correct, and that the assembly and all its dependencies are available. IRLBigBoard
Sorry but your two errors comes from it that you haven't referred a right namespace or creating a correct class。
bprego
Error 3 'System.Xml.Linq.XDocument' does not contain a definition for 'Descedants' and no extension method 'Descedants' accepting a first argument of type 'System.Xml.Linq.XDocument' could be found (are you missing a using directive or an assembly reference?) C:\mypath\Default.aspx.cs 49 62 IRLBigBoard
Make sure that you are now using net framework 3.5。
bprego
Error 4 The range variable 'e' conflicts with a previous declaration of 'e' C:\mypath\Default.aspx.cs 49 31 IRLBigBoard
bprego
Member
205 Points
46 Posts
get XML file into a grid view
Apr 12, 2012 07:27 PM|LINK
I dont think this should be this hard but obviously i am missing something. here is my XML file:
<?xml version="1.0" encoding="utf-8" ?> <Floors> <Floor>First Floor</Floor> <Departments> <Department>Pharmacy</Department> <Department>Radiology</Department> <Department>Pathology</Department> <Department>CHAMPS</Department> <Department>Audiology</Department> </Departments> <Floor>Second Floor</Floor> <Departments> <Department>Ophthalmology</Department> <Department>General Pediatrics</Department> <Department>Otolaryngology</Department> </Departments> <Floor>Third Floor</Floor> <Departments> <Department>Women's Health</Department> <Department>Women's Wellness</Department> <Department>Bone Densitometry</Department> <Department>Cardiology</Department> <Department>Urology</Department> <Department>Dermatology</Department> </Departments> <Floor>Fourth Floor</Floor> <Departments> <Department>General Internal Medicine</Department> <Department>Diabetes</Department> <Department>Digestive Diseases</Department> </Departments> </Floors>Here is the code i am uisng to get the xl file into the Grdview:
protected void Page_Load(object sender, EventArgs e) { string filePath = Server.MapPath("App_Data/IRLFacility.xml"); DataSet ds = new DataSet(); //Read the contents of the XML file into the DataSet ds.ReadXml(filePath); GridView1.DataSource = ds.Tables[0].DefaultView; GridView1.DataBind(); }This is the code on the aspx page for the grid view:
<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="true"> </asp:GridView>my output is this:
Floor_Text First Foor Second Floor Third Floor Fourth Floor But it should look more like this: First Floor Pharmacy Radiology Pathology CHAMPS Audiology Second Floor Ophthalmology General Pediatrics Otolaryngology Third Floor and so onplease help me
Thanks
kavita_khand...
Star
9767 Points
1931 Posts
Re: get XML file into a grid view
Apr 13, 2012 10:22 AM|LINK
have you considered using repeater?
I would love to change the world, but they wont give me the source code.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: get XML file into a grid view
Apr 14, 2012 01:52 AM|LINK
Hello bprego:)
【Reasons】
In fact I think you can use XmlDocument or LINQ-TO-XML and do a "nested" databinding。Something looks like this following:
【Solutions】
var result = from e in XDocument.Load("xxx.xml").Descedants("Floor") select new { FloorName = e.Value, DepartNames = from f in e.Descedants("Department") select f.Value }And then your GridView should be something like this:
<ItemTemplate>
<%#Eval("FloorName")%>
</ItemTemplate>
</asp:Template>
<asp:Template HeaderText="Departments"><ItemTemplate>
<Columns><ItemTemplate>
<%#Eval("Department")%>
</ItemTemplate>
</Columns></ItemTemplate>
</asp:Template>
Your code-behind is:bprego
Member
205 Points
46 Posts
Re: get XML file into a grid view
Apr 16, 2012 06:04 PM|LINK
Thanks Decker... I used your code and your gridview and got nothing to display so I am still looking for a complete answer if anyone is willing. Thanks in advance
Here is he code and the grid view that didnt work.
protected void Page_Load(object sender, EventArgs e) { string filePath = Server.MapPath("App_Data/test.xml"); var result = from f in XDocument.Load(filePath).Descendants("Floor") select new { FloorName = f.Value, DepartNames = from g in f.Descendants("Department") select g.Value }; } <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="false" Enabled="true" Visible="true" OnLoad="gvload"> <Columns> <asp:TemplateField HeaderText="FloorName"> <ItemTemplate><%#Eval("FloorName")%></ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Departments"> <ItemTemplate><%#Eval("Department")%></ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: get XML file into a grid view
Apr 17, 2012 01:24 AM|LINK
Sorry……
You should know that "Departments" is another collection nested in the collection of result,So plz nest another GridView inside the ItemTemplate of the outer GridView,and then do databinding:-)
Sample codes:
<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="false" Enabled="true" Visible="true" OnLoad="gvload">
<Columns>
<asp:TemplateField HeaderText="FloorName">
<ItemTemplate><%#Eval("FloorName")%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Departments">
<ItemTemplate>
<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="false" DataSource='<%#Eval("Departments")%'>……>
<Columns>
<asp:TemplateField HeaderText="Department">
<ItemTemplate>
<%#Eval("Department")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
bprego
Member
205 Points
46 Posts
Re: get XML file into a grid view
Apr 17, 2012 05:39 PM|LINK
No matter how you slice it Dong, this does not work as you have described it. if I am missing something then "I dont know what it is" or I wouldnt be here asking for help. So before you continue with trying to degrade me for asking for a little help, maybe you should try giving a complete and detailed answer that doesnt assume we know what you are talking about.
This is my code and it currently does NOT work. PLease help with a complete answer.
asp.net <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" Enabled="true" Visible="true" GridLines="None" HorizontalAlign="Center" Width="100%" CellPadding="5" CellSpacing="1"> <RowStyle Font-Size="X-Large" HorizontalAlign="Center" BackColor="#3E3E3D" ForeColor="White" /> <AlternatingRowStyle BackColor="White" ForeColor="Black" /> <HeaderStyle Font-Bold="True" Font-Size="XX-Large" BackColor="#D7AD3B" /> <Columns> <asp:TemplateField HeaderText="Floor"> <ItemTemplate><%#Eval("Floor")%></ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Department"> <ItemTemplate> <div> <asp:GridView id="GridView4" runat="server" AutoGenerateColumns="false" DataSource='<%#Eval("DeptName")%>' > <Columns> <asp:TemplateField HeaderText="Department"> <ItemTemplate> <%#Eval("DeptName")%> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> code behind: protected void Page_Load(object sender, EventArgs e) { string filePath3 = Server.MapPath("App_Data/test.xml"); var result = from f in XDocument.Load(filePath3).Descendants("Floor") select new { FloorName = f.Value, DepartNames = from g in f.Descendants("DeptName") select g.Value }; }Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: get XML file into a grid view
Apr 18, 2012 01:07 AM|LINK
Hello bprego:)
Sorry but in the nested GridView's DataSource you should say "DepartNames" instead of "DeptName"……;Well,plz attention to my complete codes——
【cs code-behind】
protected void Page_Load(object sender, EventArgs e) { string filePath3 = Server.MapPath("App_Data/test.xml"); var result = from f in XDocument.Load(filePath3).Descendants("Floor") select new { FloorName = f.Value, DepartNames = from g in f.Descendants("DeptName") select g.Value }; }【aspx codes】
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: get XML file into a grid view
Apr 18, 2012 01:19 AM|LINK
Hello bprego:)
Kindly correct me If I'm wrong,and if anything urgent,send your whole proj with xml file directly to v-dedong@microsoft.com,and I'll analyze it if I have free time……
Reguards!
bprego
Member
205 Points
46 Posts
Re: get XML file into a grid view
Apr 18, 2012 03:51 PM|LINK
how is this for kindly correcting you. I took you literally this time! and posted your code in exactly as you posted it! i even changed my XMLfile name to xxx.xml for you. Got the following errors as stated below below!! I am not sending you my project when i have posted all the code here already.
Error 1 ; expected C:\mypath\Default.aspx.cs 55 27 IRLBigBoard
Error 2 The "EntityClean" task could not be loaded from the assembly c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.Build.Tasks.dll. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Confirm that the <UsingTask> declaration is correct, and that the assembly and all its dependencies are available. IRLBigBoard
Error 3 'System.Xml.Linq.XDocument' does not contain a definition for 'Descedants' and no extension method 'Descedants' accepting a first argument of type 'System.Xml.Linq.XDocument' could be found (are you missing a using directive or an assembly reference?) C:\mypath\Default.aspx.cs 49 62 IRLBigBoard
Error 4 The range variable 'e' conflicts with a previous declaration of 'e' C:\mypath\Default.aspx.cs 49 31 IRLBigBoard
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: get XML file into a grid view
Apr 19, 2012 01:00 AM|LINK
No,you cannot change to xxx.xml as a filename,this is only an example;and you should change it to your real xml name。
Sorry but your two errors comes from it that you haven't referred a right namespace or creating a correct class。
Make sure that you are now using net framework 3.5。
What's IRlBigBoard?