Home > ASP.Net > Add DropdownList to Header of Gridview

Add DropdownList to Header of Gridview


Hi

try this example to Add DropdownList to Header of Gridview :-

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    // check if its a header row, if so then add the ddl
    if (e.Row.RowType == DataControlRowType.Header)
    {
        // create the new ddl
        DropDownList ddl = new DropDownList();
        //add items here
        ddl.AutoPostBack = true;
        ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
        // add the ddl to the row and cell of the header
        e.Row.Cells[0].Controls.Add(ddl);
    }
}

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. kingjulien
    May 5, 2011 at 11:58 am

    Wow, you da man…

    Thanks.. that saved so much of time…

  2. yasserzaid
    May 14, 2011 at 6:11 am

    @kingjulien :- you are welcome

  3. Gbahe
    November 11, 2013 at 6:12 pm

    Thanks a lot! I have been looking for this for a moment

    • yasserzaid
      December 5, 2013 at 9:59 am

      @Gbahe : you are welcome hope my post helps you

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: