Insert and remove Template textbox column in grid view

Posted by user1545215 on Stack Overflow See other posts from Stack Overflow or by user1545215
Published on 2013-10-28T05:24:39Z Indexed on 2013/10/28 9:54 UTC
Read the original article Hit count: 147

Filed under:
|

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.

Anyone know how to remove this text box template column?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about gridview