Greg,
See below
--
Regards
John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_auth or_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_autho r_plug>
----------------------------------------------
The XML file (test.xml)
<Elements>
<Links>
<Text>Wrox Press</Text>
<Link>http://www.wrox.com</Link>
</Links>
<Links>
<Text>Microsoft </Text>
<Link>http://www.microsoft.c om</Link>
</Links>
<Links>
<Text>Amazon</Text>
<Link>http://www.amazon.com</Link>
</Links>
</Elements>
<%@ Page Language="C#" %>
<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.IO" %>
<html>
<script runat="server">
string SortExpression;
DataView getData(){
DataSet ds = new DataSet();
FileStream fs = new FileStream( Server.MapPath( "test.xml") ,
FileMode.Open, FileAccess.Read );
StreamReader reader = new StreamReader( fs );
ds.ReadXml( reader );
fs.Close();
DataView dv = new DataView(ds.Tab les[0] );
dv.Sort=SortExp ression;
return dv;
}
void Page_Load(Objec t sender, EventArgs e)
{
ItemsGrid.DataS ource=getData() ;
ItemsGrid.DataB ind();
}
void Sort_Grid(objec t sender, DataGridSortCom mandEventArgs e){
SortExpression = e.SortExpressio n.ToString();
ItemsGrid.DataS ource = getData();
ItemsGrid.DataB ind();
}
</script>
<body>
<form runat="server">
<h3>DataGrid Example</h3>
<b>Product List</b>
<asp:DataGrid id="ItemsGrid"
BorderColor="bl ack"
BorderWidth="1"
CellPadding="3"
HeaderStyle-BackColor="#00a aaa"
AutoGenerateCol umns="true"
AllowSorting="t rue"
OnSortCommand=" Sort_Grid"
runat="server">
</asp:DataGrid>
</form>
</body>
</html>
"Greg Linwood" <g_************ *************** ******@hotmail. com> wrote in
message news:eU******** ******@TK2MSFTN GP11.phx.gbl...
I found an example of how to bind array data to a datagrid, but haven't
seen anything on how to bind XML directly to a datagrid.
Are there any examples you could point out for me that bind xml directly
to datagrid John?
Or do you have to have a function that iterates the xml & converts it to
the array for binding?
Regards,
Greg Linwood
SQL Server MVP
"John Timney (Microsoft MVP)" <ti*****@despam med.com> wrote in message
news:eD******** ******@TK2MSFTN GP12.phx.gbl... bind it directly to a datagrid, it renders a table as its output
automatically.
--
Regards
John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_auth or_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_autho r_plug>
----------------------------------------------
"Greg Linwood" <g_************ *************** ******@hotmail. com> wrote
in message news:#j******** ******@TK2MSFTN GP09.phx.gbl... I am wondering what the best approach to binding XML data to an asp:Table from the Page_Load event in a code behind module?
I'm using VB.Net and initially approached this by adding a table to
the web page from the VS2003 ASP page designer, extracting an XML document
from SQL Server during Page_Load, then adding asp:TableRows & asp:TableCells
one at a time / loading the corresponding xml values a cell at a time.
Is there a better (less code / maintenance) approach?
Regards,
Greg Linwood
SQL Server MVP