How to Make a HTML Table by C# code in asp.net programming
How to Make a HTML Table by C# code in asp.net programming :
As we know that we can make Html table in Asp.net by C# code ; so first we need to use
using System.Text;
Then use
StringBuilder sb = new StringBuilder();
Means make the object of StringBuilder Class ;
the use Append() function and all table's html code in this string .
then print this string in a control. as like we use literal control,
now here we give a Example :
Code in .aspx.cs file :
StringBuilder sb = new StringBuilder();
sb.Append("<table border='.5' style='border-style: groove;width:100%'>");
sb.Append("<tr>");
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col1: ID </td>");
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col 2 :Name</td>");
sb.Append("<table border='.5' style='border-style: groove;width:100%'>");
sb.Append("<tr>");
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col1: ID </td>");
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col 2 :Name</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col1: ID </td>");
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col 2 :Name</td>"); sb.Append("</tr>")
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col1: ID </td>");
sb.Append("<td style='width:50px;color: #FFFFFF' bgcolor='#333333'>col 2 :Name</td>"); sb.Append("</tr>")
sb.Append("<tr>");
sb.Append("<td style='width:50px;>col1: ID </td>");
sb.Append("<td style='width:50px>col 2 :Name</td>");
sb.Append("<td style='width:50px;>col1: ID </td>");
sb.Append("<td style='width:50px>col 2 :Name</td>");
sb.Append("</tr>") ;
sb.Append("<tr>");
sb.Append("<td style='width:50px;>col1: ID </td>");
sb.Append("<td style='width:50px>col 2 :Name</td>");
sb.Append("<td style='width:50px;>col1: ID </td>");
sb.Append("<td style='width:50px>col 2 :Name</td>");
sb.Append("</tr>") ;
sb.Append("</table>")
Literal1.Text = sb.ToString();
Code in .aspx page :
<table style="width: 100%">
<tr>
<td align="center" colspan="2">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</td>
</tr>
</table>
Result:
Col 1 :ID Col
|
Col 2: Name
|
( HTML table By C# Code )
Other Asp.net related post:
- Show gridview Row Details in Asp.net.
- Template field in gridview asp.net Example
- Example of Templatefield in asp.net gridview.
- Example of DropDownList inside GridView control
- How to use table for ListView layout in asp.net
- How to use table layout in ListView control in ASP.Net
- How to use Asp ListView control in asp.net
- ASP.NET ListView Demo Data and layout templates
- Ckeckbox list Example using javascript in gridview.
- Asp.net textbox control in inside of gridview
- How to Bind Gridview Form database.
- Show gridview Row Details And Give Example.
- Introduction of Asp.net grid view Control.
- Checkboxlist control in asp net
it might help to others
ReplyDeletehttp://www.code-sample.com/2014/09/angularjs-documentation.html
Hi,
ReplyDeleteThanks for sharing this codding. This same codding I have got from Hostbuddy.com recently. But your post is easier than him. So I am able to understand this codding part is an easy way.