I looked through the forum, but could not find an answer (I hope, I didn't miss it) ... I would like to customize a GridView class that is based on a LLBLGenProDataSource2 so that certain formatting issues are based on the meta-information of the entity columns.
For example, I would like to align content of all cells that are numeric to the right, or have all PK columns automatically as read-only.
What I am not able to find, is which methods of the GridView/BoundField (or is it the DataSource?) class I have to extend/override.
I'm looking forward to some hints.
EDIT:
I have started out like this:
public class GridView : System.Web.UI.WebControls.GridView
{
public GridView()
:
base()
{
// do nothing (for now)
}
override protected void OnRowDataBound(GridViewRowEventArgs e)
{
base.OnRowDataBound(e);
GridViewRow gridRow = e.Row;
if (gridRow.RowType == DataControlRowType.DataRow)
{
IEntityFields2 rowFields = null;
if (gridRow.DataItem is IEntity2)
{
IEntity2 row = gridRow.DataItem as IEntity2;
rowFields = row.Fields;
}
else if (gridRow.DataItem is DataRowView)
{
DataRowView dataView = gridRow.DataItem as DataRowView;
if (dataView.Row.Table is ITypedView2)
{
ITypedView2 row = dataView.Row.Table as ITypedView2;
rowFields = row.GetFieldsInfo();
}
}
if (rowFields == null)
{
throw new ArgumentException(String.Format("Illegal type of DataItem in GridView " +
"'{0}'. Expected IEntity2, found {1}.",
this.ID, gridRow.DataItem.GetType()));
}
else
{
FormatRowCells(gridRow, rowFields);
}
}
}
protected void FormatRowCells(GridViewRow gridRow, IEntityFields2 dataFields)
{
foreach (TableCell cell in gridRow.Cells)
{
// what now?
}
}
}
But now I'm not sure how to format the cells of the gridRow since a cell can theoretically span over more than one column. So I can't get the information about to which column the cell belongs. Or I am at the wrong "point" since cell.AssociatedHeaderCellID is empty ... ?
EDIT2:
I figured out some stuff for the FormatRowCells method:
protected void FormatRowCells(GridViewRow gridRow, IEntityFields2 dataFields)
{
foreach (TableCell cell in gridRow.Cells)
{
DataControlFieldCell gridCell = cell as DataControlFieldCell;
GridField field = gridCell.ContainingField as GridField;
IEntityField2 dataField = dataFields[field.DataField];
if (dataField != null
&& dataField.DataType.Name.Contains("Int"))
{
cell.CssClass = mergeCssClass(cell.CssClass, "numeric");
}
if (dataField.IsPrimaryKey)
{
field.ReadOnly = true;
}
}
}
GridField is "my" class that extends <asp:BoundField>. The check for the "numeric" class is of course not perfect, but as a prototype it works.
What I am wondering about is, the fact that the IFieldInfo.DataType class has so many methods of type isXXX, but no isNumeric() method ... or am I just looking at the wrong place?