Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to retrieve the data in a table in sql server to a HTML table in Asp.Net.Can anyone provide me the source code for that.
Posted

You can get the data in a dataset and then use a div and assign runat = server property to it. Then you can use string builder to create the HTML table as shown below.

C#
StringBuilder strResults = new StringBuilder();

strResults.Append("<table>");


for (int i = 0; i <= ds.tables(0).rows.Count; i++) {
    strResults.Append("<tr>");

    strResults.Append("<td>");
    strResults.Append(ds.tables(0).rows(i)("ColumnName"));

    strResults.Append("</td>");

    strResults.Append("<tr>");

}

strResults.Append("</table>");

divResults.innerHTML = strResults.ToString();


found it here[^]
 
Share this answer
 
Here is an example:

VB
Dim da As New SqlDataAdapter(Query, conn)
            Dim table As New DataTable()
            da.Fill(table)


            Dim filename As String = "temp.html"
            Dim sbrHTML As System.Text.StringBuilder
            sbrHTML = New System.Text.StringBuilder()
            sbrHTML.Append("<TABLE Border=1px cellspacing=0 cellpadding=0>")
            sbrHTML.Append("<tr align='Center'><td colspan='16'>Report of " & DropDownList11.SelectedItem.ToString() & " For 2011-2012</td></tr>")
 
Share this answer
 
Comments
Raghavanand 10-Sep-12 8:19am    
Thanks for the reply, I would be thankful if you send me the same code in c#
sahabiswarup 11-Sep-12 1:46am    
http://developerfusion.com/ this site will help you to convert..
Here i have just posted basic code; you have to started this way and finally save appended string into a temporary html file and display that html.

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