|
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
namespace CodeWorks
{
/// <summary>
/// Summary description for CheckBoxFieldTemplate.
/// </summary>
public class CheckBoxFieldTemplate : ITemplate
{
private Color _selectColor;
private Color _unSelectColor;
private string _columnName = "";
private int _rowReference = 0;
public CheckBoxFieldTemplate(Color selectColor, Color unSelectColor)
{
this._selectColor = selectColor;
this._unSelectColor = unSelectColor;
}
public CheckBoxFieldTemplate(string columnName,Color selectColor, Color unSelectColor)
{
this._selectColor = selectColor;
this._unSelectColor = unSelectColor;
this._columnName = columnName;
}
public void InstantiateIn(Control container)
{
_rowReference += 1;
CheckBox chkSelect = new CheckBox();
chkSelect.DataBinding += new EventHandler(this.OnDataBinding);
chkSelect.Attributes.Add("onClick", "return HighLightRow(this," + _rowReference.ToString()+ ",'" + this._selectColor.Name + "','" + this._unSelectColor.Name + "');");
chkSelect.EnableViewState=true;
container.Controls.Add(chkSelect);
}
public void OnDataBinding(object sender, EventArgs e)
{
if (this._columnName.Length > 0)
{
CheckBox chk = (CheckBox)sender;
DataGridItem container =
(DataGridItem)chk.NamingContainer;
chk.Checked = Convert.ToBoolean(((DataRowView)container.DataItem)[this._columnName]);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.