|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
namespace TemplateGridView
{
public class TemplateGridView : GridView
{
#region EditItemTemplate
private IBindableTemplate _EditItemTemplate;
private bool _EnableTemplateEditing;
public bool EnableTemplateEditing
{
get { return _EnableTemplateEditing; }
set { _EnableTemplateEditing = value; }
}
[PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(GridViewRow), System.ComponentModel.BindingDirection.TwoWay)]
public IBindableTemplate EditItemTemplate
{
set { _EditItemTemplate = value; }
get { return _EditItemTemplate; }
}
protected override void ExtractRowValues(System.Collections.Specialized.IOrderedDictionary fieldValues, GridViewRow row, bool includeReadOnlyFields, bool includePrimaryKey)
{
if (_EnableTemplateEditing)
{
IOrderedDictionary dict = _EditItemTemplate.ExtractValues(row.Cells[0]);
foreach (string s in dict.Keys)
fieldValues.Add(s, dict[s]);
}
else
base.ExtractRowValues(fieldValues, row, includeReadOnlyFields, includePrimaryKey);
}
protected override void InitializeRow(GridViewRow row, DataControlField[] fields)
{
DataControlRowState state = row.RowState & DataControlRowState.Edit;
if (row.RowType == DataControlRowType.DataRow && state != DataControlRowState.Normal && _EnableTemplateEditing == true)
{
int ColSpan = fields.Length;
row.Cells.Clear();
TableCell cell = new TableCell();
cell.ColumnSpan = ColSpan;
_EditItemTemplate.InstantiateIn(cell);
row.Cells.Add(cell);
}
else
base.InitializeRow(row, fields);
}
#endregion
protected override void OnInit(EventArgs e)
{
if (_EnableTemplateEditing && _EditItemTemplate == null)
throw new Exception("You have to enter EditItemTemplate to use TemplateEditing!");
base.OnInit(e);
}
}
}
|
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.