471,317 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Critique Request: CheckBoxColumn

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,

--
Sean
Feb 15 '06 #1
0 995

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by aacool | last post: by
19 posts views Thread by TC | last post: by
9 posts views Thread by bowsayge | last post: by
188 posts views Thread by christopher diggins | last post: by
39 posts views Thread by Eric | last post: by
reply views Thread by Fao, Sean | last post: by
2 posts views Thread by winston | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.