473,671 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=".|follo wing-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 4088
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.goo gle.com...
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=".|follo wing-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
1423
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 </b></font></td>") Response.Write("<td><font face=""Verdana"" size=""2""><b> Description </b></font></td>") ' make a couple of column headers
2
364
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 ? 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.
1
3363
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 information in other table columns. To make the collapse / expand functionality I want to use JavaScript to display / hide table rows using row.style.display = "inline" / "none". To get references to the table rows they all need unique id's. I want
1
3139
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 possible to do that?? if so, any sample for me as i am a new in designing pivot table with asp.net million thanks
3
1272
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 have the same name "commercial", so my Javascript function does'nt work. I try different way to do this, but can't find the solution.
3
3826
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 dataset to dynamically create a Html Table control. I want to display the table on another frame page (target="main") without the web form controls (i.e. the textbox, search button, and dropdown list). I just want the table displayed only on the...
1
6343
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 dataset to dynamically create a Html Table control. I want to display the table on another frame page (target="main") without the web form controls (i.e. the textbox, search button, and dropdown list). I just want the table displayed only on the...
2
1685
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")) Quesion 1 - the above is the command to run the "PublishHTML" procedures... i want to know if the file path is dynamic change, and is changed according to the time when user install the application. if there is a way to change to something like...
2
2690
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. Not all line items need to have the same columns as some products vary greatly in data attributes. How do I set up my tables to allow for Dynamic Columns based on the line item type. I have tried creating another table that holds attribute names and...
0
8481
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8924
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
8602
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
8672
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7441
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...
1
6234
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
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...
2
2058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1814
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.