Click here to Skip to main content
14,922,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my default.aspx code(create a table with 1 row and 2 cells)
XML
<div id="id1">
    <table>
    <tr>
    <td>
        <asp:DropDownList ID="DropDownList1" runat="server" 
            DataSourceID="SqlDataSource1" DataTextField="firstname" 
            DataValueField="firstname" AppendDataBoundItems="true" >
            <asp:ListItem  Text="All" Value="-1" />
        
        </td>
        <td>
        <asp:Button ID="Button1" runat="server" BackColor="#E1E1E1" 
            Text="Display Report" onclick="Button1_Click" OnClientClick="html()" />
            </td>
           
            </tr>
</table>
</div>


This is my default.aspx.cs code..Here i ahve created dynamically table using stringbuilder..
C#
StringBuilder strhtmlcontent = new StringBuilder();
//table starts
strhtmlcontent.Append("<table align="Center" style="background-color:#" border-collapse:collapse="" cellspacing="0" rules="all" border="1" width="100%" xmlns:border-collapse="#unknown"><th width="8%" bgcolor="#DFDFFF">FirstName</th><th width="10%" bgcolor="#DFDFFF">Product Name</th><th width="10%" bgcolor="#DFDFFF">Client Name</th><th width="10%" bgcolor="#DFDFFF">Amount</th><th width="10%" bgcolor="#DFDFFF">Activity Date</th>");

strhtmlcontent.Append("</table>");
//table Ends


When i run the project.. table created in default.aspx page is below that of dynamically created table..

Means like this
//table1 (dynamic using stringbuilder)
below
//table2 (static on aspx page)

But i want...like this

//table2 (static on aspx page)
below
//table1 (dynamic using stringbuilder.)

thanks
Posted
Updated 20-Feb-12 4:30am
v3

If you were able to successfully append, you could insert as well using StringBuilder.Insert(int, string), call it with zero index.

—SA
   
v2
In your aspx page, you could also use an asp:Literal control to define the location where you want table2 to appear.
i.e.
aspx:
XML
<asp:literal id="litTable1" runat="server" xmlns:asp="#unknown" />
<table id="table1" ...="">
   ...
</table>

.cs:
C#
...
StringBuilder strhtmlcontent = new StringBuilder();
// build your table
litTable1.Text = strhtmlcontent;
   
Comments
BobJanova 20-Feb-12 11:29am
   
5 for this, it's what I would have typed except I couldn't remember the tag/property names :p
fjdiewornncalwe 20-Feb-12 12:44pm
   
Thanks. I find that I have to do this a lot more often than I would like, so it remains fresh in my memory.
Sergey Alexandrovich Kryukov 20-Feb-12 12:08pm
   
Right, a 5. I would just repeat what Bob have said above. :-)
--SA
fjdiewornncalwe 20-Feb-12 12:45pm
   
Thanks.
Espen Harlinn 20-Feb-12 12:18pm
   
Good reply Marcus :)
fjdiewornncalwe 20-Feb-12 12:45pm
   
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900