title: Cannot get/use ControlParameter from GridView in a TemplateField SELECT statement
body: <p>I have a simple GridView (with an ID of 'GridViewAttribs') which displays some values from a database.</p>
  
  <p>Within my GridViewAttribs I wish to have a (nested?) ListView but for some reason I cannot use the asp:ControlParameter ControlID="GridViewAttribs" PropertyName as no results are returned in my (nested) ListView.</p>
  
  <p>If I do NOT use the ControlParameter and hardcode my SELECT statement for the ListView, everything works as expected. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDataSourceAttribHeadings" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:customer_support_devConnectionString %&gt;" 
      ProviderName="&lt;%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %&gt;" 
      SelectCommand="SELECT equipment_attrib_heading_id, equipment_model_id, equipment_attrib_name FROM equipment_new_attrib_headings WHERE (equipment_model_id = @equipment_model_id) AND (equipment_attrib_heading_deleted = 0) ORDER BY equipment_attrib_name"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:SessionParameter DefaultValue="" Name="equipment_model_id" 
              SessionField="EquipmentModelID" Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  
  &lt;asp:GridView ID="GridViewAttribs" runat="server" AutoGenerateColumns="False" 
      CellPadding="4" DataKeyNames="equipment_attrib_heading_id" 
      DataSourceID="SqlDataSourceAttribHeadings" ForeColor="#333333" GridLines="None" 
      style="margin-right: 0px"&gt;
      &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="equipment_attrib_heading_id" 
              HeaderText="equipment_attrib_heading_id" ReadOnly="True" 
              SortExpression="equipment_attrib_heading_id" /&gt;
          &lt;asp:BoundField DataField="equipment_model_id" HeaderText="equipment_model_id" 
              SortExpression="equipment_model_id" /&gt;
          &lt;asp:BoundField DataField="equipment_attrib_name" 
              HeaderText="equipment_attrib_name" SortExpression="equipment_attrib_name" /&gt;
  
          &lt;asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details"&gt;
              &lt;ItemTemplate&gt;
  
                  &lt;asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server" 
                      ConnectionString="&lt;%$ ConnectionStrings:customer_support_devConnectionString %&gt;" 
                      ProviderName="&lt;%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %&gt;" 
                      SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = @head_id) AND (equipment_id = @equipment_id) AND (equipment_attrib_value_deleted = 0)"&gt;
                      &lt;SelectParameters&gt;
                          &lt;asp:QueryStringParameter Name="equipment_id" QueryStringField="id" 
                              Type="Int32" /&gt;
                          &lt;asp:ControlParameter ControlID="GridViewAttribs" 
                              Name="head_id" PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]" Type="Int32" /&gt;
                      &lt;/SelectParameters&gt;
                  &lt;/asp:SqlDataSource&gt;
  
                  &lt;asp:ListView ID="ListViewAttribValues" runat="server" 
                      DataSourceID="SqlDataSourceAttribValues"&gt;
                      &lt;EmptyDataTemplate&gt;
                          &lt;table runat="server" style=""&gt;
                              &lt;tr&gt;&lt;td&gt;No data was returned.&lt;/td&gt;&lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/EmptyDataTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;tr style=""&gt;
                              &lt;td&gt;&lt;asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='&lt;%# Eval("equipment_attrib_value_details") %&gt;' /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;LayoutTemplate&gt;
                          &lt;table ID="itemPlaceholderContainer" runat="server" border="0" style=""&gt;
                              &lt;tr ID="itemPlaceholder" runat="server"&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/LayoutTemplate&gt;
                  &lt;/asp:ListView&gt;
  
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
  
      &lt;/Columns&gt;
  
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>The GridView displays all columns fine except the "equipment_attrib_value_details" column where I get "No data was returned."</p>
  
  <p>However, if I take out the asp:ControlParameter which calls upon @head_id and use this hardcoded SELECT statement then I see the correct (albeit hardcoded) values:</p>
  
  <pre><code>SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = 3) AND (equipment_id = @equipment_id) AND (equipment_attrib_value_deleted = 0)"&gt;
  </code></pre>
  
  <p>Therefore, for some reason, it would appear that the GridViewAttribs value of "equipment_attrib_heading_id" is not being passed to / picked up by the nested asp:ControlParameter</p>
  
  <p>On the off chance, I've also tried replacing:</p>
  
  <pre><code>PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]"
  </code></pre>
  
  <p>With:</p>
  
  <pre><code>PropertyName="SelectedValue"
  </code></pre>
  
  <p>But this didn't resolve the issue either, still not data was returned.</p>
  
  <p>If it helps, I'm using Visual Studio 2010 with ASP.NET4 (vb).</p>