title: updating a sql table with a datagridview using template field
body: <p>so the thing is i want to limit what can the user insert when updating through a datagridview. i thought of converting that specific field into a template and make it a dropdownlist with limited options to update such field. the thing is that when i run tests with this it updates the field as null. the sqldatasource bound to the datagridview updates perfectly fine without the template field.</p>
  
  <p>i was able to make this work on a table without much problem but when i tried the same thing for another table it kept giving me a null value on the dropdownlist. this latter is bound to a SqlDataSource. i checked the code on the gridview and the data source and its pretty much the same. i don't see whats the problem.</p>
  
  <p>This is the code of my SqlDataSource</p>
  
  <pre><code>    &lt;asp:SqlDataSource ID="SqlCoord" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:sistema_gestion_calidadConnectionString %&gt;" 
          OldValuesParameterFormatString="original_{0}"
          SelectCommand="SELECT profesor.nombre + ' ' + profesor.apellidos AS Expr1, materia.nombre_materia, coordinadores.id_coordinador, coordinadores.id_materia, coordinadores.id_profesor FROM coordinadores INNER JOIN materia ON coordinadores.id_materia = materia.id_materia INNER JOIN profesor ON coordinadores.id_profesor = profesor.id_profesor"             
          UpdateCommand="UPDATE coordinadores SET id_materia = @id_materia, id_profesor = @id_profesor FROM coordinadores INNER JOIN profesor ON coordinadores.id_profesor = profesor.id_profesor INNER JOIN materia ON coordinadores.id_materia = materia.id_materia WHERE (coordinadores.id_coordinador = @original_id_coordinador)"&gt;
          &lt;UpdateParameters&gt;
              &lt;asp:Parameter Name="id_materia" /&gt;
              &lt;asp:Parameter Name="id_profesor" /&gt;
              &lt;asp:Parameter Name="original_id_coordinador" /&gt;
          &lt;/UpdateParameters&gt;
      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>And this is my DataGridview</p>
  
  <pre><code>    &lt;asp:GridView ID="GridView2" runat="server" AllowPaging="True" 
          AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="id_coordinador" 
          DataSourceID="SqlCoord" CellPadding="4" ForeColor="#333333" 
          GridLines="None"&gt;
          &lt;AlternatingRowStyle BackColor="White" /&gt;
          &lt;Columns&gt;
              &lt;asp:CommandField ShowEditButton="True" /&gt;
              &lt;asp:TemplateField HeaderText="Profesor" SortExpression="Profesor"&gt;
                  &lt;EditItemTemplate&gt;
                      &lt;asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlProfs" 
                          DataTextField="Expr1" DataValueField="id_profesor"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;asp:SqlDataSource ID="SqlProfs" runat="server" 
                          ConnectionString="&lt;%$ ConnectionStrings:sistema_gestion_calidadConnectionString %&gt;" 
                          SelectCommand="SELECT id_profesor, nombre + ' ' + apellidos AS Expr1 FROM profesor"&gt;
                      &lt;/asp:SqlDataSource&gt;
                  &lt;/EditItemTemplate&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Expr1") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="nombre_materia" SortExpression="nombre_materia"&gt;
                  &lt;EditItemTemplate&gt;
                      &lt;asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlMats" 
                          DataTextField="nombre_materia" DataValueField="id_materia"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;asp:SqlDataSource ID="SqlMats" runat="server" 
                          ConnectionString="&lt;%$ ConnectionStrings:sistema_gestion_calidadConnectionString %&gt;" 
                          SelectCommand="SELECT [id_materia], [nombre_materia] FROM [materia]"&gt;
                      &lt;/asp:SqlDataSource&gt;
                  &lt;/EditItemTemplate&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("nombre_materia") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:BoundField DataField="id_coordinador" HeaderText="id_coordinador" ReadOnly="True" 
                  SortExpression="id_coordinador" InsertVisible="False" Visible="False" /&gt;
              &lt;asp:BoundField DataField="id_materia" HeaderText="id_materia" 
                  SortExpression="id_materia" Visible="False" /&gt;
              &lt;asp:BoundField DataField="id_profesor" HeaderText="id_profesor" 
                  SortExpression="id_profesor" Visible="False" /&gt;
          &lt;/Columns&gt;
          &lt;EditRowStyle BackColor="#7C6F57" /&gt;
          &lt;FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /&gt;
          &lt;HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /&gt;
          &lt;PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /&gt;
          &lt;RowStyle BackColor="#E3EAEB" /&gt;
          &lt;SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /&gt;
          &lt;SortedAscendingCellStyle BackColor="#F8FAFA" /&gt;
          &lt;SortedAscendingHeaderStyle BackColor="#246B61" /&gt;
          &lt;SortedDescendingCellStyle BackColor="#D4DFE1" /&gt;
          &lt;SortedDescendingHeaderStyle BackColor="#15524A" /&gt;
      &lt;/asp:GridView&gt;
  </code></pre>