W
Wee Bubba
i have just developed my first datagrid custom column. it is very
simple. i know that each cell will only display a char value of 'T'
or 'F'. so if the cell value is 'T' i am displaying a ticked checkbox
image and if it is 'F' i am displaying a blank checkbox image.
it seems to be working ok but as this is my first attempt I am posting
my code as I do not know if I have coded it the best way. many thanks
for any feedback.
public class CheckboxColumn : BoundColumn
{
public CheckboxColumn(): base()
{
}
public override void InitializeCell(TableCell cell, int
columnIndex, ListItemType itemType)
{
base.InitializeCell(cell, columnIndex, itemType);
if (itemType == ListItemType.Item || itemType ==
ListItemType.AlternatingItem)
cell.DataBinding += new
EventHandler(OnDataBinding);
}
private void OnDataBinding(object sender, EventArgs e)
{
HtmlImage hi = new HtmlImage();
if (((TableCell) sender).Text ==
"T")
hi.Src = "../images/checkbox_ticked.gif";
else
hi.Src = "../images/checkbox_blank.gif";
((TableCell)
sender).Controls.Add(hi);
}
}
[/code]
simple. i know that each cell will only display a char value of 'T'
or 'F'. so if the cell value is 'T' i am displaying a ticked checkbox
image and if it is 'F' i am displaying a blank checkbox image.
it seems to be working ok but as this is my first attempt I am posting
my code as I do not know if I have coded it the best way. many thanks
for any feedback.
public class CheckboxColumn : BoundColumn
{
public CheckboxColumn(): base()
{
}
public override void InitializeCell(TableCell cell, int
columnIndex, ListItemType itemType)
{
base.InitializeCell(cell, columnIndex, itemType);
if (itemType == ListItemType.Item || itemType ==
ListItemType.AlternatingItem)
cell.DataBinding += new
EventHandler(OnDataBinding);
}
private void OnDataBinding(object sender, EventArgs e)
{
HtmlImage hi = new HtmlImage();
if (((TableCell) sender).Text ==
"T")
hi.Src = "../images/checkbox_ticked.gif";
else
hi.Src = "../images/checkbox_blank.gif";
((TableCell)
sender).Controls.Add(hi);
}
}
[/code]