473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best approach to bind data from XML to an asp:Table

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
Nov 18 '05 #1
4 4090
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

Nov 18 '05 #2
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


Nov 18 '05 #3
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



Nov 18 '05 #4
Thanks John

That's what I'm after.

Regards,
Greg Linwood
SQL Server MVP

"John Timney (Microsoft MVP)" <ti*****@despam med.com> wrote in message
news:uX******** ******@TK2MSFTN GP11.phx.gbl...
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
>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
464
by: Stephen | last post by:
I have been getting on well with help from this forum trying to create an array list and work with it. Everything is working fine apart from displaying my array list items into the labels in my asp table. The asp table has numerous rows and each row has a label item within it. Im finding it impossible to get something to work which adds the newest item in the array list to the next row in the asp table. the first time the button is...
1
2161
by: Stephen | last post by:
I have got the below asp table and I would like to be able to call up the lblAddress1 label with in the asp table in the code behind page. I tried doing this.lblAddress1 and it didn't work and I tried doing this.tblSearchAddresses.lblAddress1 and it didn't work. Has anyone an idea how I call this lable with a asp table. Thanks in advance for any help anyone can give me. <asp:table id="tblSearchAddresses" Runat="server" Width="100%">...
2
2684
by: Kevin | last post by:
I am just learning asp.net and ran into a problem that I have not been able to resolve. I have a web form with an html table that houses an asp:label, asp:textbox and asp:button within. I had the click event of the asp:button working. I then decided to drop an asp:table on the form and then added the three component mentioned above into the asp:table. Now I cannot find a way to set the click even of the asp:button anymore. In fact,...
4
1949
by: coleenholley | last post by:
I asked the question yesterday: > HI All :-) > > I don't know if I will be able to do this type of formatting, but what I > need to do is have a table row where the text wraps (This is easy) the first > line of text is font size 10 pt and the second (wrapped text) is 6 pt. I > know how to create a style sheet to get all of my font one size or the > other, but does any one have any suggestions on how to do this?
6
5325
by: coleenholley | last post by:
I have a Class Module written in VB that calls an RPC (written in COBOL) we have written code to read the data from the RPC, and we create a temporary datatable to store the data from the RPC. This works fine when we call the datatable and bind it to a data grid using datagridname.DataBind(), but I have an ASP table, with calculations using tbl_name.row(1).cells(1) and the result of the calculation is put in a specific row and cell. I have...
0
1396
by: Kristoffer Arfvidson | last post by:
HI! I have the following javascript events in my normal tables. onMouseOver,onMouseOut and onClick Now, when I try to put this in my asp:tablerow it just gets an error msg that literal text is not allowed in tablerow... :( When I tryed to put this table as a normal <table> it works, but, for some reason it automaticly makes an </td></tr> before the new asp:table comes in... therefore not achieving my goals in design... :(
1
12293
by: Ed West | last post by:
Hello, How can I put a textbox control into a cell of an asp:Table? I was not able to do it from the properties sheet, so I put it in via html tab, but now I can't select it from the Design tab (nor select it from the Properties tab on the right). Any ideas? <asp:Table id="Table1" runat="server"> <asp:TableRow> <asp:TableCell Text="Email:"></asp:TableCell>
4
3937
by: Nathan Sokalski | last post by:
When editing an ASP Table, Visual Studio does not allow me to edit it in Design View. This makes it harder to add elements, because I must add every element either by using Design View to create the element outside of the table and then using cut & paste in HTML View to move it to the desired location, or by manually typing the code in using HTML View. The first technique sometimes does not automatically update the list of elements...
0
1081
by: janaiah | last post by:
I have task to display the entire data table fields into Tool tip when mouse is over on data list field.
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.