Click here to Skip to main content
15,886,199 members
Articles / Web Development / HTML

ASP.NET DataGrid Extension [Client Side Sortable/Dragable....] - Part I

Rate me:
Please Sign up or sign in to vote.
4.67/5 (22 votes)
28 Feb 2008CPOL5 min read 87.2K   1.8K   71  
An extension to the ASP.NET DataGrid control with built-in client side sorting, column dragging, fixed header, check all, uncheck all, highlight selected row, and more...
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Systems Limited
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions