title: Gridview SqlDataSource ; Error with edit from dropdownlist
body: <p>I have a gridview populated with an sqldatasource. One of the columns of the gridview is a templatefield which contains a label as ItemTemplate, but in the EditItemTemplate I have a dropdownlist, instead of a textbox. I wanted to be able to edit a value from a certain column by selecting from a list of possible values.
  So I created a second sqldatasource in order to extract the values from the database. I bounded the 2 sqldatasources. Visually it's ok. When I click on edit, the dropdownlist appears with the values that I want inside of it. When I select one of the values and click update, I get the error "
  Input string was not in a correct format." I think I know why this is happening. Probably the values from the dropdownlist are type string and what I need is integer because that is the type for this column. I have tried setting the UpdateParameter as type Int32 but no luck. Is there any way to do this ? </p>
  
  <p>This is the code I have used, but I have changed the column names with "Column_1", "Column_2", etc. In this example, "Column_6" is the templatefield with the dropdownlist in the edit. </p>
  
  <pre><code>&lt;asp:GridView ID="DataUploadGridView" runat="server" AutoGenerateColumns="False" DataSourceID="First_DB" DataKeyNames="Column_3" &gt;
                  &lt;RowStyle HorizontalAlign="Center" /&gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundField DataField="Column_1" HeaderText="Column 1"/&gt;
                      &lt;asp:BoundField DataField="Column_2" HeaderText="Column 2"/&gt;
                      &lt;asp:BoundField DataField="Column_3" HeaderText="Column 3"/&gt;
                      &lt;asp:BoundField DataField="Column_4" HeaderText="Column 4"/&gt;
                      &lt;asp:BoundField DataField="Column_5" HeaderText="Column 5"/&gt;
                      &lt;asp:TemplateField HeaderText="Column 6"&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Second_DB" DataTextField="Column_6_Description" DataValueField="Column_6_ID"/&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Column_6_ID") %&gt;'/&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:CommandField ShowEditButton="true" HeaderText="Edit" /&gt;
                      &lt;asp:CommandField ShowDeleteButton="true" HeaderText="Delete" /&gt;
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
  
  &lt;asp:SqlDataSource ID="First_DB" runat="server" ConnectionString="&lt;%$ ConnectionStrings:MyConnectionString %&gt;" OnSelecting="First_DB_Selecting" OnSelected="First_DB_Selected" OnInserted="First_DB_Inserted" OnInserting="First_DB_Inserting" OnDeleting="First_DB_Deleting" OnUpdating="First_DB_Updating"
                  SelectCommand ="SELECT * FROM [tblFirst_DB] 
                  UpdateCommand ="UPDATE [tblFirst_DB] 
                  SET [Column_1] = @Column_1, 
                  [Column_2] = @Column_2, 
                  [Column_3] = @Column_3, 
                  [Column_4] = @Column_4, 
                  [Column_5] = @Column_5, 
                  [Column_6] = @Column_6 
                  WHERE [Column_3] = @Column_3" 
                  DeleteCommand ="DELETE FROM [tblFirst_DB] WHERE [Column_3] = @Column_3"
                  &lt;UpdateParameters&gt;
                      &lt;asp:Parameter Name="Column_1" Type="String" /&gt;
                      &lt;asp:Parameter Name="Column_2" Type="String" /&gt;
                      &lt;asp:Parameter Name="Column_3" Type="String" /&gt;
                      &lt;asp:Parameter Name="Column_4" Type="String" /&gt;
                      &lt;asp:Parameter Name="Column_5" Type="Int32" /&gt;
                      &lt;asp:Parameter Name="Column_6" Type="Int32" /&gt;
                  &lt;/UpdateParameters&gt;
                  &lt;DeleteParameters&gt;
                      &lt;asp:Parameter Name="Column_3" Type="String" /&gt;
                  &lt;/DeleteParameters&gt;
              &lt;/asp:SqlDataSource&gt;
  &lt;asp:SqlDataSource ID="Second_DB" runat="server" ConnectionString="&lt;%$ ConnectionStrings:MyConnectionString %&gt;" SelectCommand="SELECT [Column_6_ID], [Column_6_Description] FROM [tblSecond_DB]"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Hopefully you are still here. So just to recap the problem. I'm getting an "
  Input string was not in a correct format. " error because I need the Column_6 parameter to be integer and the values are coming from a dropdownlist which is probably making each value a string. </p>
  
  <p>What can I do so that the value for Column_6 stays int upon updating it ? 
  The only thing that comes to mind right now is to pass the parameter from the code behind somehow. When I select the dropdownlist value, I should trigger an OnSelectedIndexChanged event. I'm thinking here is where I should cast the Selected_ID to an integer and somehow feed it into the first sqldatasource. But the value would go into a label so that will turn it into a string again. So no use...I'm really stuck on this. Any help is welcome. </p>
  
  <p>Thank you !</p>
  
  <p>Update: I've noticed that if I remove all the UpdateParameters, except the one from Column_6, I'm not getting the error anymore. However the value is not going in the gridview. It's an empty cell. I looked in the DB and it's null.
  I think it's null because in the UpdateParameters I now have: </p>
  
  <pre><code>&lt;UpdateParameters&gt;
              &lt;asp:Parameter Name="Column_6" Type="Int32" /&gt;
          &lt;/UpdateParameters&gt;
  </code></pre>
  
  <p>It's not getting the value from anywhere. It should get it from the Second_DB sqldatasource. I tried changing it to:</p>
  
  <pre><code>&lt;UpdateParameters&gt;
              &lt;asp:ControlParameter Name="Column_6" ControlID="Second_DB" Type="Int32" /&gt;
          &lt;/UpdateParameters&gt;
  </code></pre>
  
  <p>But it's not really working out like I expected. I feel like I'm getting closer but no idea why it's behaving like this.</p>