Skip to main content

How to add a Text box in the Gridview Header?

 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
          
            // Check the header type
            if (e.Row.RowType == DataControlRowType.Header)
            {
                Literal litHeader;
                TextBox txtSearch;

                // loop through each cell
                for (int i = 0; i <= (e.Row.Cells.Count - 1); i++)
                {
                    litHeader = new Literal();
                    txtSearch = new TextBox();

                    // get the current header text
                    litHeader.Text = e.Row.Cells[i].Text;

                    // add the header text plus a new textbox
                    e.Row.Cells[i].Controls.Add(litHeader);
                    e.Row.Cells[i].Controls.Add(txtSearch);
                }

            }
        }

Comments

Popular posts from this blog