var fields = GetListOfFieldsFromDB(); foreach (var f in fields) { var c = new System.Web.Helpers.WebGridColumn(); c.ColumnName = f.FieldName; c.Header = f.FieldAlias; c.CanSort = true; switch (f.SqlDataType) { case "datetime": c.Format = (item) => string.Format("{0:dd MMM yyyy}", item.DontKnowTheNameOfTheFieldYet; // Need help here . break; case "decimal": c.Format = item => item.ToString("C"); // Need more help here. // No clue what the syntax should be. break; // some more formats here ... } columnList.Add(c); }
var grid = new WebGrid(source: Model.Records, canPage: true, rowsPerPage: 20); @grid.GetHtml(tableStyle: "table", columns: Model.Columns)
c.Format = item => item.ToString("C"); //doesn't work
switch (f.SqlDataType) { case "datetime": c.Format = item => string.Format("{0:dd MMM yyyy}", item[f.FieldName]); break; case "decimal": c.Format = item => item[f.FieldName].ToString("C"); break; ... }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)