my first datagrid custom column - feedback appreciated!

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top