class TextColumn : ITemplate
{
private string controlId;
private string cssClass;
public TextColumn(string id, string cssClass = "inputFromTo")
{
controlId = id;
this.cssClass = cssClass;
}
public void InstantiateIn(Control container)
{
TextBox txt = new TextBox();
txt.ID = controlId;
txt.CssClass = cssClass;
container.Visible = true;
container.Controls.Add(txt);
}
}
/************************************ Add column code snippet ****************************/
TemplateField dentry = new TemplateField();
TemplateField dexit = new TemplateField();
TemplateField dslack = new TemplateField();
dentry.ItemTemplate = new TextColumn("txtHH" + nameCount + "DEntry");
dexit.ItemTemplate = new TextColumn("txtHH" + nameCount + "DExit");
dslack.ItemTemplate = new TextColumn("txtHH" + nameCount + "DSlack");
gvOfcBlowingReport.Columns.Insert(startPoint, dentry);
gvOfcBlowingReport.Columns.Insert(startPoint + 1, dexit);
gvOfcBlowingReport.Columns.Insert(startPoint + 2, dslack);
/********************************* Remove column code snippet ************************/
gvOfcBlowingReport.Columns.RemoveAt(startPoint - 1);
gvOfcBlowingReport.Columns.RemoveAt(startPoint - 2);
gvOfcBlowingReport.Columns.RemoveAt(startPoint - 3);
// after executing this code all the columns vanish.
任何人都知道如何删除此文本框模板列?
在上面的代码中,我添加模板化字段文本框,稍后在按钮单击时删除相同但由于某些原因所有模板化字段都受到影响,并且当我在网格中使用FindControl时返回null
。在显示中,网格也显示为空。
其他一些人在http://forums.asp.net/t/1162011.aspx上也遇到了同样的问题,但到目前为止还没有有价值的解决方案。