title: How to insert a DropDownList inside the GridView's first header
body: <p>I have a GridView where I have some data and also another HTML table right above with the DropDownList to filter the GridView. The only issue is, because they are two separate tables, the column doesn't match up. To make up for that, inside the RowCreated method I added the following as an example:</p>
  
  <pre><code>protected void yourTasksGV_RowCreated(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.Header)
      {
          GridView hGrid = (GridView)sender;
          GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
          TableHeaderCell tcCell = new TableHeaderCell();
          tcCell.Text = @"&lt;asp:DropDownList ID='ddlTaskName2' CssClass='chosen-select' DataSourceID='dsPopulateTaskName2' AutoPostBack='true' DataValueField='Task Name' runat='server' Width='100%' Font-Size='11px' AppendDataBoundItems='true' OnSelectedIndexChanged='ddlTaskName_onSelectIndexChanged'&gt;
                                      &lt;asp:ListItem Text='All' Value='%'&gt;&lt;/asp:ListItem&gt;
                                  &lt;/asp:DropDownList&gt;
                                  &lt;asp:SqlDataSource ID='sPopulateTaskName2' runat='server' ConnectionString='&lt;%$ ConnectionStrings:gvConnString %&gt;' SelectCommand=\""SELECT [actionname] from [OnBase].[hsi].[action]\""&gt;&lt;/asp:SqlDataSource&gt;";
          tcCell.ColumnSpan = 1;
          gvrRow.Cells.Add(tcCell);
  
          TableHeaderCell tcCell2 = new TableHeaderCell();
          tcCell2.Text = "TEST #2";
          tcCell2.ColumnSpan = 1;
          gvrRow.Cells.Add(tcCell2);
  
  
          yourTasksGV.Controls[0].Controls.AddAt(0, gvrRow);
      }
  }
  </code></pre>
  
  <p>I don't see any DropDownList when the GridView is created.</p>
  
  <p>My table that I am using for filtering is this:</p>
  
  <pre><code>&lt;table class="taskGridView" runat="server"&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateTaskName" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlService" CssClass="chosen-select" DataSourceID="dsPopulateService" AutoPostBack="true" DataValueField="Service" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlService_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateService" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlStatus" CssClass="chosen-select" DataSourceID="dsPopulateStatus" AutoPostBack="true" DataValueField="Status" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlStatus_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateStatus" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlDueDate" CssClass="chosen-select" DataSourceID="dsPopulateDueDate" AutoPostBack="true" DataValueField="Due Date" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlDueDate_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateDueDate" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlOwner" CssClass="chosen-select" DataSourceID="dsPopulateOwner" AutoPostBack="true" DataValueField="Owner" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlOwner_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateOwner" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlClient" CssClass="chosen-select" DataSourceID="dsPopulateClient" AutoPostBack="true" DataValueField="Client" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlClient_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateClient" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlSite" CssClass="chosen-select" DataSourceID="dsPopulateSite" AutoPostBack="true" DataValueField="Site" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlSite_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateSite" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlPractice" CssClass="chosen-select" DataSourceID="dsPopulatePractice" AutoPostBack="true" DataValueField="Practice" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlPractice_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulatePractice" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:DropDownList ID="ddlProvider" CssClass="chosen-select" DataSourceID="dsPopulateProvider" AutoPostBack="true" DataValueField="Provider" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlProvider_onSelectIndexChanged"&gt;
                  &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="dsPopulateProvider" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand=""&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I am populating the SelectCommand from code-behind on Page_Load. I am also calling another function on Page_Load which references the DropDownList but I get a <code>The name 'DropDownList ID' does not exist in current content</code></p>
  
  <p>My GridView:</p>
  
  <pre><code>&lt;asp:GridView ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="You currently have no tasks assigned to you" OnRowDataBound="yourTasksGV_RowDataBound" OnRowCreated="yourTasksGV_RowCreated"&gt;
      &lt;Columns&gt;
          &lt;asp:HyperLinkField Target="_self" DataNavigateUrlFields="Task Detail" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Detail" SortExpression="Task Name" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Service" HeaderText="Service" SortExpression="Service" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Due Date" HeaderText="Due" SortExpression="Due Date" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Site" HeaderText="Site" SortExpression="Site" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Practice" HeaderText="Practice" SortExpression="Practice" ItemStyle-CssClass="taskTableColumn" /&gt;
          &lt;asp:BoundField DataField="Provider" HeaderText="Provider" SortExpression="Provider" ItemStyle-CssClass="taskTableColumn" /&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>What I want to do is take the DropDownList table and insert it inside the GridView HEADER right above the Header that is being generated.</p>
  
  <p>As you can see in the below image the empty header where the DropDownList is supposed to go is there but I don't see anything. That's where I would like to put the DropDownList with the <code>all</code> option.</p>
  
  <p><img src="https://i.stack.imgur.com/909k0.png" alt="enter image description here"></p>