[C #] DataTables.net: dynamic columns in number and name
[C #] DataTables.net: dynamic columns in number and name
robertino_salemi
Posts: 13Questions: 0Answers: 0
Hello,
I'm using your DataTables.
Until now I used the DataTables creating a model with fixed columns of the table and then populating a DataTable with C #.
But now I need to create a dynamic header, ie with the number and name of columns that vary in construction to those present in the DataTable C #.
I can not figure it out, suggestions?
Thank you.
I'm using your DataTables.
Until now I used the DataTables creating a model with fixed columns of the table and then populating a DataTable with C #.
But now I need to create a dynamic header, ie with the number and name of columns that vary in construction to those present in the DataTable C #.
I can not figure it out, suggestions?
Thank you.
This discussion has been closed.
Replies
[code]
public static class DataTableExtension
{
public static MvcHtmlString ToHTMLTableDataTable(this DataTable model, string id)
{
string table = @"
";
foreach (System.Data.DataColumn column in model.Columns)
{
table += "" + column.Caption + "";
}
table += @"
";
foreach (System.Data.DataRow row in model.Rows)
{
table += " ";
foreach (System.Data.DataColumn column in model.Columns)
{
table += "" + row[column].ToString() + "";
}
table += "";
}
table += "";
return new MvcHtmlString(string.Format("{1}", id, table));
}
[/code]