473,387 Members | 1,904 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,387 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 4065
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...
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...

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.