Well your first step should be read though the link I provided along with the examples. You can always set the xpath fileting expression in code. It's a good opportunity to get your hands dirty with xpath.
Well your first step should be read though the link I provided along with the examples. You can always set the xpath fileting expression in code. It's a good opportunity to get your hands dirty with xpath.
Hi,
From my understanding, you would like to using XPath to select special attribute value in your xml code.
If so, please try to refer to the following code:
protected void Page_Load(object sender, EventArgs e)
{
XmlDataSource1.XPath = "employeeinformationbyday";
var xmldoc = XDocument.Parse(XmlDataSource1.Data);
var groups = xmldoc.Root.XPathSelectElements("/employeeinformationbyday/emp");
var names = from q in groups.AsEnumerable()
select new { name = q.Attribute("empname").Value };
DataTable dt = new DataTable();
dt.Columns.Add("empname");
foreach (var item in names)
{
DataRow dr;
dr = dt.NewRow();
dr["empname"] = item.name;
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
If you have any question, please let me know.
Best Regards,
Terry Guo
Thanks for your post
Your code produce me output
empname
Samanta
Lusia
Andria
L. Katuia
Lusia
Henry
Wilson
Smith
Jack
Andrina
I need output only
Samanta
Andria
L. Katuia
Select those name where OfficeTime="today"
except LINQ
You can use collection
---- Mark It As A Answer If It Helps You --- Thanks ... asp.net1
Interested in Azure, ASP.NET (MVC), jQuery, WCF, Silverlight, EF, MS SQL, ...
Member
67 Points
205 Posts
GridView binding from XmlDataSource data source
Aug 25, 2013 03:01 AM|asp.net1|LINK
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<Data>
<employeeinformationbyday>
<emp empid="1" empname="Samanta" genid="1" OfficeTime="today" />
<emp empid="2" empname="Lusia" genid="11" OfficeTime="yesterday" />
<emp empid="2" empname="Andria" genid="100" OfficeTime="today" />
<emp empid="3" empname="L. Katuia" genid="1000" OfficeTime="today" />
<emp empid="4" empname="A. Joly" genid="113" OfficeTime="tomorrow" />
</employeeinformationbyday>
</Data>
</asp:XmlDataSource>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = XmlDataSource1;
GridView1.DataBind();
}
Underline code provie me this output
I Need to show those data in GridView only where OfficeTime="today"
protected void Page_Load(object sender, EventArgs e)
{
// Write code here
// Data Source = XmlDataSource1
}
Output :
Samanta
Andria
L. Katuia
Please write the code for this without LINQ
Interested in Azure, ASP.NET (MVC), jQuery, WCF, Silverlight, EF, MS SQL, ...
All-Star
101931 Points
20703 Posts
Re: GridView binding from XmlDataSource data source
Aug 25, 2013 03:19 AM|MetalAsp.Net|LINK
Specify the XPath to filter on your desired criteria.
Refer:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.xpath.aspx
Member
67 Points
205 Posts
Re: GridView binding from XmlDataSource data source
Aug 25, 2013 04:55 AM|asp.net1|LINK
thanks for your replay
I am confused about ur replay please clear it... I need to write code under page_load event
Interested in Azure, ASP.NET (MVC), jQuery, WCF, Silverlight, EF, MS SQL, ...
All-Star
101931 Points
20703 Posts
Re: GridView binding from XmlDataSource data source
Aug 25, 2013 05:18 AM|MetalAsp.Net|LINK
Well your first step should be read though the link I provided along with the examples. You can always set the xpath fileting expression in code. It's a good opportunity to get your hands dirty with xpath.
Member
67 Points
205 Posts
Re: GridView binding from XmlDataSource data source
Aug 25, 2013 05:39 AM|asp.net1|LINK
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication5.NewFolder4.WebForm4" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:XmlDataSource ID="XmlSource" DataFile="bookstore.xml" runat="server" XPath="bookstore/genre[@name='fiction']" />
<asp:Repeater ID="Repeater1" DataSourceID="XmlSource" runat="server">
<ItemTemplate>
<h1>
<%# XPath ("book/title") %></h1>
<b>Price:</b>
<%# XPath ("book/price") %>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<genre name="fiction">
<book ISBN="0000000000">
<title>Secrets of Silicon Valley</title>
<price>12.95</price>
<chapters>
<chapter num="1" name="Introduction" />
<chapter num="2" name="Body" />
<chapter num="3" name="Conclusion" />
</chapters>
</book>
</genre>
<genre name="novel">
<book genre="novel" ISBN="1111111111">
<title>Straight Talk About Computers</title>
<price>24.95</price>
<chapters>
<chapter num="1" name="Introduction" />
<chapter num="2" name="Body" />
<chapter num="3" name="Conclusion" />
</chapters>
</book>
</genre>
</bookstore>
Produce Output :
Secrets of Silicon Valley
Price: 12.95
then what is the next step?
Interested in Azure, ASP.NET (MVC), jQuery, WCF, Silverlight, EF, MS SQL, ...
Star
12777 Points
1635 Posts
Re: GridView binding from XmlDataSource data source
Aug 29, 2013 06:04 AM|Terry Guo - MSFT|LINK
Hi,
From my understanding, you would like to using XPath to select special attribute value in your xml code.
If so, please try to refer to the following code:
If you have any question, please let me know.
Best Regards,
Terry Guo
Member
67 Points
205 Posts
Re: GridView binding from XmlDataSource data source
Sep 01, 2013 04:07 AM|asp.net1|LINK
Thanks for your post
Your code produce me output
I need output only
Samanta
Andria
L. Katuia
Select those name where OfficeTime="today"
except LINQ
You can use collection
Interested in Azure, ASP.NET (MVC), jQuery, WCF, Silverlight, EF, MS SQL, ...