2
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.

任何人都知道如何删除此文本框模板列?

在上面的代码中,我添加了模板化字段文本框,然后在单击按钮时删除了相同的文本框,但由于某种原因,null当我在网格中使用 FindControl 时,所有模板化字段都会受到影响并返回。在显示中,网格也显示为空。

其他一些人在http://forums.asp.net/t/1162011.aspx也面临同样的问题,但到目前为止还没有有价值的解决方案。

4

0 回答 0