using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.IO;
using AspNet = System.Web.UI.WebControls;
namespace ExtAspNet.Examples.data
{
public class GenderTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
AspNet.TextBox labGender = new AspNet.TextBox();
labGender.ID = "tbxSex";
labGender.DataBinding += new EventHandler(labGender_DataBinding);
container.Controls.Add(labGender);
}
作者: shiningrise 时间: 2012-10-22 07:50
为了更好使用模板列
我作了以下改动,建议更新到官方源文件里GridRow.cs
/// <summary>
/// 初始化模板容器
/// </summary>
public void InitTemplateContainers()
{
GridColumnCollection columns = _grid.AllColumns;
if (TemplateContainers == null)
{
TemplateContainers = new GridRowControl[columns.Count];
}
//针动动态添加的模板列,要相应增加TemplateContainers的长度
if (TemplateContainers.Length < columns.Count)
{
GridRowControl[] newGridRowControlContainers = new GridRowControl[columns.Count];
for (int i = 0; i < TemplateContainers.Length; i++)
{
newGridRowControlContainers[i] = TemplateContainers[i];
}
TemplateContainers = newGridRowControlContainers;
}
for (int i = 0, count = columns.Count; i < count; i++)
{
GridColumn column = columns;
if (column is TemplateField)
{
if (TemplateContainers[column.ColumnIndex] == null)
{
TemplateField field = column as TemplateField;
GridRowControl control = new GridRowControl(DataItem, RowIndex);
//control.ID = String.Format("{0}_{1}_{2}", Grid.ID, RowIndex, column.ColumnIndex);
control.ID = String.Format("c{0}r{1}", column.ColumnIndex, RowIndex);