Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ConvertDataTableToHTML
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { DataTable dt = new DataTable(); dt.Columns.Add("Subject"); dt.Columns.Add("Code"); dt.Columns.Add("Test"); dt.Columns.Add("Class"); dt.Rows.Add("Math", "9", "ABC", "D1"); dt.Rows.Add("Math", "9", "ABD", "D2"); dt.Rows.Add("Math", "9", "ABE", "D3"); dt.Rows.Add("Math", "9", "ABF", "D4"); dt.Rows.Add("Science", "91", "ABG", "D1"); dt.Rows.Add("Science", "91", "ABH", "D2"); dt.Rows.Add("Science", "91", "ABI", "D3"); dt.Rows.Add("English", "191", "ABJ", "D1"); var a = ConvertDataTableToHTML(dt); Console.Write(a); } public static string ConvertDataTableToHTML(DataTable dt) { string html = "<table border=1>"; //add header row html += "<tr>"; for (int i = 0; i < dt.Columns.Count; i++) { html += "<td>" + dt.Columns[i].ColumnName + "</td>"; } html += "</tr>"; //add rows string sub = ""; for (int i = 0; i < dt.Rows.Count; i++) { html += "<tr>"; int count = dt.Select("Subject ='" + dt.Rows[i][0].ToString() + "'").Count(); for (int j = 0; j < dt.Columns.Count; j++) { if (j < 1) { if (sub != dt.Rows[i][0].ToString()) { html += "<td rowspan='" + count + "'>" + dt.Rows[i][j].ToString() + "</td>"; } continue; } html += "<td>" + dt.Rows[i][j].ToString() + "</td>"; } sub = dt.Rows[i][0].ToString(); html += "</tr>"; } html += "</table>"; return html; } } }
run
|
edit
|
history
|
help
0
Write a program to count the occurrence of each distinct item in the array?
Rozwiazanie
Random IF OR
Intuit // C# // listing_4.2 (Converting / Parsing)
C# - out parameters and reference parameters
ray's 2nd test
Random number string changer
Stuff
Serialization
Get UTC time and offset minutes