473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HTML Table with Dynamic Columns

Hello

Does anyone know how to display data from a data source such as an
array or SqlDataReader or XML etc within an HTML table whose number of
columns can change according to the value of a variable ?

This is one thing that XSL is brilliant at but I can't find a nice
..Net solution

The following is how it can easily be achieved in XSL.

-------- XML file -------------

<root>
<letter>a</letter>
<letter>b</letter>
<letter>d</letter>
<letter>c</letter>
<letter>f</letter>
<letter>e</letter>
<letter>g</letter>
<letter>h</letter>
<letter>i</letter>
</root>

------- XSL file --------------

<xsl:template match="root">
<xsl:variable name="columns" select="6" />
<TABLE>
<xsl:for-each select="letter[position() mod $columns = 1]">
<TR>
<xsl:for-each select=".|following-sibling::letter[position()
&lt; $columns]">
<TD>
<xsl:value-of select="." />
</TD>
</xsl:for-each>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
Nov 12 '05 #1
1 4067
In .NET 1.1, you could load the XML into a DataSet and then bind the DataSet
to a DataGrid (which will get rendered as a HTML table).
In ASP.NET 2.0, there is an XmlDataSource control which makes your job even
easier.

But if you don't want to use the DataGrid in .NET 1.1, you could write a few
lines of code to write out a table by iterating through the DataRows in the
first DataTable of the DataSet.

Mujtaba.

"Fresh Air Rider" <Fr*************@Hotmail.com> wrote in message
news:55**************************@posting.google.c om...
Hello

Does anyone know how to display data from a data source such as an
array or SqlDataReader or XML etc within an HTML table whose number of
columns can change according to the value of a variable ?

This is one thing that XSL is brilliant at but I can't find a nice
.Net solution

The following is how it can easily be achieved in XSL.

-------- XML file -------------

<root>
<letter>a</letter>
<letter>b</letter>
<letter>d</letter>
<letter>c</letter>
<letter>f</letter>
<letter>e</letter>
<letter>g</letter>
<letter>h</letter>
<letter>i</letter>
</root>

------- XSL file --------------

<xsl:template match="root">
<xsl:variable name="columns" select="6" />
<TABLE>
<xsl:for-each select="letter[position() mod $columns = 1]">
<TR>
<xsl:for-each select=".|following-sibling::letter[position()
&lt; $columns]">
<TD>
<xsl:value-of select="." />
</TD>
</xsl:for-each>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>

Nov 12 '05 #2

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

Similar topics

3
by: HenryW | last post by:
I have a section of ASP code that dynamically builds a table. And per usual it writes out to the table like so: Response.Write("<td><font face=""Verdana"" size=""2""><b> Status...
2
by: Fresh Air Rider | last post by:
Hello Does anyone know how to display data from a data source such as an array or SqlDataReader etc within an HTML table whose number of columns can change according to the value of a variable ?...
1
by: OM | last post by:
I am trying to present tree-structure information using a html table and JavaScript. Each tree node is displayed in the first column in a table row. The tree node can also have additional...
1
by: Grey | last post by:
I have created a asp.net form for user to input data. After input the data, user need to click a button to export the input data to excel for data analysis with excel pivot table function. is it...
3
by: Andre | last post by:
Hi, I have a <ItemTemplate> with a HTML Table inside, "id=commercial" who display Ads on our site. But for each Store, i have to put a different CSS Class name to my Table, but all the table...
3
by: Al Wilkerson | last post by:
Hey, I have a Web Form with a drop down list, textbox, and search button. When click the search button an SQL server database is queried fordata. Once I have the data in a dataset I use the...
1
by: Al Wilkerson | last post by:
Hey, I have a Web Form with a drop down list, textbox, and search button. When click the search button an SQL server database is queried fordata. Once I have the data in a dataset I use the...
2
by: PK | last post by:
Hi All, i got few questions to ask regarding about publishing dataset to html format !!! ------------------- PublishHTML("C:\Inetpub\wwwroot\Report.htm", myDataSet1.Tables("table01")) ...
2
by: mhuff | last post by:
Hello, I have a table called ticket that has tickets stored in it. I have a seperate table called line items with the line items in it that are tied back to the ticket via a foreignkey. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.