my first datagrid custom column - feedback appreciated!

Discussion in 'ASP .Net' started by Wee Bubba, Sep 28, 2004.

  1. Wee Bubba

    Wee Bubba Guest

    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]
     
    Wee Bubba, Sep 28, 2004
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.