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

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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




    Murtix Van Basten Guest

  2. Similar Questions and Discussions

    1. Why doesn't the Code Completion occur in FlexBuilder IDEwhen source code is in an external file?
      I am seperating my .as from the MXML by using the following in my file.mxml: <mx:Script source="file.as"> When I edit file.as, the code...
    2. Custom control fires event but ignores some code in the code behind file
      I do not quite understand the question. I will merely point out that most programming problems happen for a reason. Code works the way it is...
    3. help with rss creating code creating an XML rss feed]
      When I run the following code I get the follwing error and cant really see the problem I am incxluding this file from another page thanks in...
    4. creating table - can't
      I've read around, especially at mysql.com to see if there are any limitations to tablenames, one is 64 characters and the other one seems to be...
    5. Creating a table using the IXF file format for data exported using a SELECT * statement
      Hello, everyone. Which of the following is being kept in the new table? Check constraints Catalog statistics Primary key definitions
  3. #2

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

    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" <rdagdelenj31@comNO-SPAMcast.net> wrote in message
    news:V6KcnVurUsQ2p2SjXTWJhg@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
    >
    >
    >
    >

    PJ Guest

  4. #3

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

    PJ,

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

    Murtix.


    "PJ" <pjwalNOSPAM@hotmail.com> wrote in message
    news:#$90YauODHA.2476@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" <rdagdelenj31@comNO-SPAMcast.net> wrote in message
    > news:V6KcnVurUsQ2p2SjXTWJhg@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
    > >
    > >
    > >
    > >
    >
    >

    Murtix Van Basten Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139