473,396 Members | 1,871 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.

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.Tables["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.aspx?dno=row[0].ToString()>Click 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 5165
PJ
Create your table w/ the LiteralControl. The LiteralControl takes as it's
constructor a string argument...which 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(DataTable dt)
{
StringBuilder mytable = new StringBuilder("<table width=/"100%/">");
for each ( DataRow dr in dt )
{
mytable.Append(GetRow(dr));
}
mytable.Append("</table>");
myPlaceHolder.Controls.Add(new LiteralControl(myTable.ToString()));
}

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

// ~PJ

"Murtix Van Basten" <rd**********@comNO-SPAMcast.net> wrote in message
news:V6********************@comcast.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.Tables["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.aspx?dno=row[0].ToString()>Click 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*********@hotmail.com> wrote in message
news:#$**************@TK2MSFTNGP10.phx.gbl...
Create your table w/ the LiteralControl. The LiteralControl takes as it's
constructor a string argument...which 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(DataTable dt)
{
StringBuilder mytable = new StringBuilder("<table width=/"100%/">");
for each ( DataRow dr in dt )
{
mytable.Append(GetRow(dr));
}
mytable.Append("</table>");
myPlaceHolder.Controls.Add(new LiteralControl(myTable.ToString()));
}

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

// ~PJ

"Murtix Van Basten" <rd**********@comNO-SPAMcast.net> wrote in message
news:V6********************@comcast.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.Tables["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.aspx?dno=row[0].ToString()>Click

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
by: Jan Danielsson | last post by:
Hello all, Is there any way to create a file with a specified size?
2
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...
2
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) );...
3
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
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
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...
4
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...
4
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...
5
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...
1
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...
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.