Critique Request: CheckBoxColumn

F

Fao, Sean

I recently had the desire to create a CheckBoxColumn (similar to a
ButtonColumn) that I could add to a DataGrid. I believe the 2.0
framework already includes such a type; however, this is for an ASP.NET
1.1 project.

Could anybody please give me some feedback on my implementation?

<code>
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace MyProject.Controls
{
/// <summary>
/// Summary description for CheckBoxColumn.
/// </summary>
public class CheckBoxColumn : DataGridColumn, INamingContainer
{
private bool _checked; /// Determines whether CheckBox
/// in CheckBoxColumn is checked
private bool _enableviwestate; /// Determines whether object
/// persists its ViewState
private string _id; /// The unique identifier for the
/// control

/// <summary>
/// Gets or sets a value that determines whether the
/// CheckBoxColumn is checked
/// </summary>
[DefaultValue(false), Description("CheckBox_Checked"),
Bindable(true)]
public bool Checked
{
get
{
return this._checked;
}
set
{
this._checked = value;
}
}

/// <summary>
/// Gets or sets a value indicating whether object persists its
/// ViewState
/// </summary>
[Description("Control_MaintainState"), DefaultValue(true),
Category("Behavior")]
public bool EnableViewState
{
get
{
return this._enableviwestate;
}
set
{
this._enableviwestate = value;
}
}

/// <summary>
/// Gets or sets the unique identifier of the CheckBoxColumn
/// </summary>
[MergableProperty(false), ParenthesizePropertyName(true),
Description("Control_ID")]
public string ID
{
get
{
return this._id;
}
set
{
this._id = value;
}
}

/// <summary>
/// Creates an instance of a CheckBoxColumn
/// </summary>
public CheckBoxColumn()
{
}

/// <summary>
/// Implements base method to reset the specified cell to its
/// initial value
/// </summary>
/// <param name="cell">A System.Web.UI.WebControls.TableCell
/// that represents the cell to reset</param>
/// <param name="columnIndex">Resets the specified cell to its
/// initial value</param>
/// <param name="itemType">Resets the specified cell to its
/// initial value</param>
public override void InitializeCell(TableCell cell, int
columnIndex, ListItemType itemType)
{
base.InitializeCell (cell, columnIndex, itemType);

if ((itemType != ListItemType.Header) && (itemType !=
ListItemType.Footer))
{
CheckBox checkbox = new CheckBox();

checkbox.Checked = this._checked;
checkbox.EnableViewState = this._enableviwestate;
checkbox.ID = this._id;

cell.Controls.Add(checkbox);
}
}
}
}
</code>

I had to manually replace tabs with spaces so I hope that turned out
alright.

Thank you in advance,
 

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,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top