Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > creating on-the-fly asp:table in the code file

Reply
Thread Tools

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

 
 
Murtix Van Basten
Guest
Posts: n/a
 
      06-25-2003
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




 
Reply With Quote
 
 
 
 
PJ
Guest
Posts: n/a
 
      06-25-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>



 
Reply With Quote
 
 
 
 
Murtix Van Basten
Guest
Posts: n/a
 
      06-25-2003
PJ,

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

Murtix.


"PJ" <(E-Mail Removed)> wrote in message
news:#$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: creating python code with dynamic file name Dave Angel Python 0 05-15-2009 12:33 PM
Creating a DLL file from Python Code macedo.silva@gmail.com Python 2 03-09-2007 09:55 PM
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM
"Error Creating Control" when creating a custom control (Design Time). Can't see tooltip message. Ravi Ambros Wallau ASP .Net Web Controls 0 06-01-2005 02:36 PM
"Error Creating Control" when creating a custom control (Design Time). Can't see tooltip message. Ravi Ambros Wallau ASP .Net 0 06-01-2005 02:36 PM



Advertisments