Yesterday I set out to do two things with the CustomGridView.
First, I wanted to show the grid even when there was no data (similar to what the GridView does), but I also wanted the headers to show (something the GridView does not do).
That was easily accomplished by overriding CreateChildControls - check out
http://dotnetslackers.com/GridView/r...ta_Exists.aspx if you're interested.
The scond one, adding a CheckBox, proved more challenging. Not creating the field, but setting it to the right value on the RowDataBound event.
I added the following function to CustomGridView.cs:
Code:
public void AddBoundCheckBox(string dataField, string headerText, string sortExpression)
{
CheckBoxField cbf = newCheckBoxField();
if (dataField != "")
cbf.DataField = dataField;
if (headerText != "")
cbf.HeaderText = headerText;
if (sortExpression != "")
cbf.SortExpression = sortExpression;
Columns.Add(cbf);
}
Getting the value set was a lot more challenging (for me). Here's what I ultimately came up with (variable names changed from my code) in the RowDataBound event handler:
Code:
((CheckBox)e.Row.Cells[COL_INDEX_CONST].Controls[0]).Checked = ((baseEO)e.Row.DataItem).SomeBooleanProperty;
This works....but I'm wondering if there's an easier/better way to do this?
Tim