I know how to get from this:
DataTable table = new DataTable(); table.Columns.Add("ID", typeof(int)); table.Columns.Add("Name", typeof(string)); table.Columns.Add("Age", typeof(int)); table.Rows.Add(1, "Bob", 35); table.Rows.Add(2, "Sam", 44); table.Rows.Add(3, "Ann", 26); SimpleGrid1.DataSource = table; SimpleGrid1.DataBind();
:
------------------------------- | ID: 1 | Name: Bob | Age: 35 | ------------------------------- | ID: 2 | Name: Sam | Age: 44 | ------------------------------- | ID: 3 | Name: Ann | Age: 26 | -------------------------------
Withdraw from ITemplate:
public class CustomColumnDefiner : ITemplate { ...
Add a public field to CustomColumnDefiner for the column name and ListItemType.
override this function in CustomColumnDefiner:
void ITemplate.InstantiateIn(System.Web.UI.Control container)
In InstantiateIn, if the ListItemType is ListItemType.Item, check the column name. If the column name is Age, change the value of the inbound label to Age: + the inbound value. This is basically the post-processing of each cell in the column to add the "Age:" part.
On the installation side there is such a function:
private static TemplateField GetTemplateColumn(string sColName) { TemplateField templateField = new TemplateField(); templateField.HeaderTemplate = new CustomColumnDefiner(ListItemType.Header, sColName); templateField.ItemTemplate = new CustomColumnDefiner(ListItemType.Item, sColName); return templateField; }
and then in your aspx page code.
myGridView.Columns.Add(GetTemplateColumn("Age"));
I used this method to bend GridViews as I wanted. It will work to transition from your datatable to the html table you want. Will it fit into your overall decision, I do not know.