Click here to Skip to main content
15,849,829 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)
<div id="id1">
        <asp:DropDownList ID="DropDownList1" runat="server" 
            DataSourceID="SqlDataSource1" DataTextField="firstname" 
            DataValueField="firstname" AppendDataBoundItems="true" >
            <asp:ListItem  Text="All" Value="-1" />
        <asp:Button ID="Button1" runat="server" BackColor="#E1E1E1" 
            Text="Display Report" onclick="Button1_Click" OnClientClick="html()" />

This is my default.aspx.cs code..Here i ahve created dynamically table using stringbuilder..
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>");

//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)
//table2 (static on aspx page)

But i this

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

Updated 20-Feb-12 5:30am

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

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

StringBuilder strhtmlcontent = new StringBuilder();
// build your table
litTable1.Text = strhtmlcontent;
Share this answer
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. :-)
fjdiewornncalwe 20-Feb-12 12:45pm    
Espen Harlinn 20-Feb-12 12:18pm    
Good reply Marcus :)

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