473,756 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating on-the-fly asp:table in the code file

Hi,

I dont know it is doable, but I wanna ask it anyway.

I am pulling 5 different data from a datatable row by row. So each row
has 5 fields and row count is variable not a constant. So, each row's fields
will be shown in a table in a different design. That means, I cannot use
DataGrid, because the view should be different. Here is the html:table
structure fo each datarow:

<table>
for (int i=0;i<DataSet.T ables["mytable"].Rows.Count;i++ )
{
DataRow row = DataSet.Tables["myTable"].Rows[i];
// from here the html table's rows are being entered
<tr>
<td width=18%><img src=row[4].ToString()></td>
<td colspan=2>row[2].ToString()</td>
</tr>
<tr>
<td rowspan=2>&nbsp ;</td>
<td rowspan=2 width=54%>row[5].ToString()</td>
<td width=28%>row[3].ToString()</td>
</tr>
<tr>
<td>row[1].ToString</td>
</tr>
<tr>
<td colspan=3><a href=details.as px?dno=row[0].ToString()>Cli ck Here
For More Info</a></td>
</tr>
}
</table>

As you have seen here, the table row count cannot be known, so I will
have to create tablerows as much as the datarow goes.

I have tried to do it with Rersponse.Write , but it is writing all of
these on top of the page, and it is ruining the design. I have tried to use
the <asp:Table> object, but it needs the <asp:TableRow > and <asp:TableCell> s
to be declared at design time. I wanted to do it inline of the aspx page, it
has given alot of runtime errors regarding to the compilation. (Because I am
using VS.NET and I am writing the code behind, not in the aspx files.)

So, how can I create these table rows on-the-fly ? Or I am kind of hoping
that, there must be another command, that does similar thing Response.Write
command does, but it puts the code whereever I want to be put.

Thanks and Regards.

Murtix Van Basten


Nov 17 '05 #1
2 5185
PJ
Create your table w/ the LiteralControl. The LiteralControl takes as it's
constructor a string argument...whic h is the html. Build that string with a
StringBuilder object.
Put a PlaceHolder control on the aspx page and add a the new LiteralControl
to the PlaceHolder control. Something like this:

private void MakeTable(DataT able dt)
{
StringBuilder mytable = new StringBuilder(" <table width=/"100%/">");
for each ( DataRow dr in dt )
{
mytable.Append( GetRow(dr));
}
mytable.Append( "</table>");
myPlaceHolder.C ontrols.Add(new LiteralControl( myTable.ToStrin g()));
}

private string GetRow(DataRow dr)
{
//do the processing on the row
}

// ~PJ

"Murtix Van Basten" <rd**********@c omNO-SPAMcast.net> wrote in message
news:V6******** ************@co mcast.com...
Hi,

I dont know it is doable, but I wanna ask it anyway.

I am pulling 5 different data from a datatable row by row. So each row
has 5 fields and row count is variable not a constant. So, each row's fields will be shown in a table in a different design. That means, I cannot use
DataGrid, because the view should be different. Here is the html:table
structure fo each datarow:

<table>
for (int i=0;i<DataSet.T ables["mytable"].Rows.Count;i++ )
{
DataRow row = DataSet.Tables["myTable"].Rows[i];
// from here the html table's rows are being entered
<tr>
<td width=18%><img src=row[4].ToString()></td>
<td colspan=2>row[2].ToString()</td>
</tr>
<tr>
<td rowspan=2>&nbsp ;</td>
<td rowspan=2 width=54%>row[5].ToString()</td>
<td width=28%>row[3].ToString()</td>
</tr>
<tr>
<td>row[1].ToString</td>
</tr>
<tr>
<td colspan=3><a href=details.as px?dno=row[0].ToString()>Cli ck Here For More Info</a></td>
</tr>
}
</table>

As you have seen here, the table row count cannot be known, so I will
have to create tablerows as much as the datarow goes.

I have tried to do it with Rersponse.Write , but it is writing all of
these on top of the page, and it is ruining the design. I have tried to use the <asp:Table> object, but it needs the <asp:TableRow > and <asp:TableCell> s to be declared at design time. I wanted to do it inline of the aspx page, it has given alot of runtime errors regarding to the compilation. (Because I am using VS.NET and I am writing the code behind, not in the aspx files.)

So, how can I create these table rows on-the-fly ? Or I am kind of hoping
that, there must be another command, that does similar thing Response.Write command does, but it puts the code whereever I want to be put.

Thanks and Regards.

Murtix Van Basten

Nov 17 '05 #2
PJ,

Thank you very much. It is exactly what I was looking for.

Murtix.
"PJ" <pj*********@ho tmail.com> wrote in message
news:#$******** ******@TK2MSFTN GP10.phx.gbl...
Create your table w/ the LiteralControl. The LiteralControl takes as it's
constructor a string argument...whic h is the html. Build that string with a StringBuilder object.
Put a PlaceHolder control on the aspx page and add a the new LiteralControl to the PlaceHolder control. Something like this:

private void MakeTable(DataT able dt)
{
StringBuilder mytable = new StringBuilder(" <table width=/"100%/">");
for each ( DataRow dr in dt )
{
mytable.Append( GetRow(dr));
}
mytable.Append( "</table>");
myPlaceHolder.C ontrols.Add(new LiteralControl( myTable.ToStrin g()));
}

private string GetRow(DataRow dr)
{
//do the processing on the row
}

// ~PJ

"Murtix Van Basten" <rd**********@c omNO-SPAMcast.net> wrote in message
news:V6******** ************@co mcast.com...
Hi,

I dont know it is doable, but I wanna ask it anyway.

I am pulling 5 different data from a datatable row by row. So each row has 5 fields and row count is variable not a constant. So, each row's fields
will be shown in a table in a different design. That means, I cannot use
DataGrid, because the view should be different. Here is the html:table
structure fo each datarow:

<table>
for (int i=0;i<DataSet.T ables["mytable"].Rows.Count;i++ )
{
DataRow row = DataSet.Tables["myTable"].Rows[i];
// from here the html table's rows are being entered
<tr>
<td width=18%><img src=row[4].ToString()></td>
<td colspan=2>row[2].ToString()</td>
</tr>
<tr>
<td rowspan=2>&nbsp ;</td>
<td rowspan=2 width=54%>row[5].ToString()</td>
<td width=28%>row[3].ToString()</td>
</tr>
<tr>
<td>row[1].ToString</td>
</tr>
<tr>
<td colspan=3><a href=details.as px?dno=row[0].ToString()>Cli ck

Here
For More Info</a></td>
</tr>
}
</table>

As you have seen here, the table row count cannot be known, so I will have to create tablerows as much as the datarow goes.

I have tried to do it with Rersponse.Write , but it is writing all of
these on top of the page, and it is ruining the design. I have tried to

use
the <asp:Table> object, but it needs the <asp:TableRow > and

<asp:TableCell> s
to be declared at design time. I wanted to do it inline of the aspx page, it
has given alot of runtime errors regarding to the compilation. (Because
I am
using VS.NET and I am writing the code behind, not in the aspx files.)

So, how can I create these table rows on-the-fly ? Or I am kind of

hoping that, there must be another command, that does similar thing

Response.Write
command does, but it puts the code whereever I want to be put.

Thanks and Regards.

Murtix Van Basten


Nov 17 '05 #3

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

Similar topics

7
7513
by: Jan Danielsson | last post by:
Hello all, Is there any way to create a file with a specified size?
2
1371
by: CsharpStudent | last post by:
There are 2 Users on PC - User1 & User2. It is necessary to assign for User1 "Full control" on file c:\test.txt & to assign for User2 "Read only" on fhat file. How can I do it using .NET framework classes & C#?
2
5814
by: jay | last post by:
hi, Question on Load/import command. consider a sample table create table table_name ( col1 timestamp not null default current timestamp, col2 int, col3 int, col4 int, primary key(col1) ); There is a file file.del containing data for col2,col3,col4. Data for
3
11728
by: GGerard | last post by:
Hello Does anyone know if it is possible with Access 2000 to create relationships between tables using code? Thanks G.Gerard
2
10647
by: Fabian | last post by:
Hi, i need to get an example, to create a Table in my Crystal Report only by having a Dataset. Can someone give me an small example please. Thx for help regards Fabian
3
2989
by: --[zainy]-- | last post by:
AA! I am having problems on creating table through Enterprise Manager. It gives me Error 1038 i.e. is as follows Unexpected Error ODBC error: Cannot use empty object or column names. Use a single space if necessary.
4
3481
by: farhad | last post by:
Hi I have a ListBox and I want write code for a CommandButton that by pressing it, a table be create with 2 column . One is contain data that in listbox and secon column is empty that I would like to enter data as number. if that data count is variable , how can I do it? Do you have another issu? Thank you so.
4
2282
by: antpal | last post by:
I am not sure exactly what i am doing run but when I run this code in sql plus i get constraint error on most of my tables except author and books table. Please help I am new to Programming in PL/SQL. --Create All Tables CREATE TABLE authors ( auth_id NUMBER(7), f_name VARCHAR2(30), l_name VARCHAR2(50),
5
2198
by: Naveen Kumar Srivastava | last post by:
Hi to All I want to create a table in oracle having name more than 16 character how i can? I know that oracle support table namt upto 28 character by default it support 15 character but i don't know how to change size. If any one know please reply me. Thanks
1
1476
by: Man4ish | last post by:
How can image be changed on row click on table? If i click a particular row, image corresponding to that row should be displayed. I know abt imagemap but not sre how to implement it. Thanks in advance
0
9455
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
9271
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
10031
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
9838
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,...
1
7242
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
5140
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...
1
3805
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
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
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.