title: passing dropdown value to update parameter for ASP.Net Gridview
body: <p>I have a gridview that, when in edit mode, I use a dropdown to load all provinces, however, when I change the province and click update, my page crashes...I'm not sending the province parameter to the gridview's updateparameters properly...here's my code, someone please help..</p>
  
  <pre><code>            &lt;asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee" Width="85%"
                      HorizontalAlign="Center"
                      Font-Bold="False" Font-Names="Verdana"
                      Font-Size="10pt" AutoGenerateColumns="False"
                      OnRowDataBound="gvUsers_RowDataBound" 
                      OnRowDeleting="gvUsers_RowDeleting" &gt;
              &lt;HeaderStyle BackColor="#904601" ForeColor="White" 
                     Font-Bold="True" HorizontalAlign="Left" /&gt;
              &lt;SelectedRowStyle BackColor="Yellow" /&gt;
              &lt;AlternatingRowStyle BackColor="White" Font-Bold="false" /&gt;
                     &lt;Columns&gt;
                           &lt;asp:TemplateField&gt;
                         &lt;ItemTemplate&gt;
                             &lt;asp:LinkButton ID="LinkButton2" 
                               CommandArgument='&lt;%# Eval("UserID") %&gt;' 
                               CommandName="Select" runat="server"&gt;
                               Select&lt;/asp:LinkButton&gt;
                           &lt;/ItemTemplate&gt;     
                           &lt;/asp:TemplateField&gt;
                          &lt;asp:BoundField DataField="UserID" Visible="False" /&gt;
                          &lt;asp:TemplateField HeaderText="Name"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("FirstName") %&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Eval("LastName") %&gt;'&gt;&lt;/asp:Label&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField HeaderText="Delete?"&gt;
                           &lt;ItemTemplate&gt;
                             &lt;asp:LinkButton ID="LinkButton1" 
                               CommandArgument='&lt;%# Eval("UserID") %&gt;' 
                               CommandName="Delete" runat="server"&gt;
                               Delete&lt;/asp:LinkButton&gt;
                           &lt;/ItemTemplate&gt;
                         &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt; 
                  &lt;RowStyle HorizontalAlign="Left" /&gt;
                &lt;/asp:GridView&gt;&lt;br /&gt;&lt;br /&gt;
                &lt;asp:DetailsView runat="server" ID="dvUser" DataSourceID="SqlDataSource1" AutoGenerateRows="False" Width="85%" DataKeyNames="UserID"
                      HorizontalAlign="Center" AutoGenerateInsertButton="True" AutoGenerateEditButton="True" OnItemInserted="dvUsers_ItemInserted" &gt;
                    &lt;Fields&gt;
                        &lt;asp:BoundField DataField="UserID" Visible="False" /&gt;
                        &lt;asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /&gt;
                        &lt;asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /&gt;
                        &lt;asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="true" SortExpression="UserName" /&gt;
                        &lt;asp:TemplateField HeaderText="Password"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label runat="server" ID="lblPassword" Text="●●●●●●●●●"&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:TextBox runat="server" ID="txtPassword" TextMode="Password" Text='&lt;%# Bind("Password") %&gt;'&gt;
                              &lt;/asp:TextBox&gt;
                          &lt;/EditItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField HeaderText="Birthdate" SortExpression="Birthdate"&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:TextBox runat="server" ID="Birthdate" Text='&lt;%# Bind("Birthdate") %&gt;' &gt;&lt;/asp:TextBox&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label runat="Server" ID="lblBirthdate" Text='&lt;%# Bind("Birthdate") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" /&gt;
                        &lt;asp:BoundField DataField="Apt" HeaderText="Apt" SortExpression="Apt" /&gt;
                        &lt;asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /&gt;
                        &lt;asp:TemplateField HeaderText="Province"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label runat="server" ID="lblProvince" Text='&lt;%# Eval("ProvName") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:DropDownList runat="server" ID="ddlProvince" DataValueField="ProvinceID" DataSourceID="SqlDataSource2" DataTextField="Province"&gt;&lt;/asp:DropDownList&gt;
                          &lt;/EditItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" /&gt;
                        &lt;asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" SortExpression="PhoneNum" /&gt;
                        &lt;asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /&gt;
                        &lt;asp:CheckBoxField DataField="ynAdminUser" HeaderText="ynAdminUser" SortExpression="ynAdminUser" /&gt;
                    &lt;/Fields&gt;
              &lt;/asp:DetailsView&gt;
              &lt;asp:SqlDataSource ID="SqlDataSource2" 
                      runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
                      SelectCommand="SELECT ProvinceID, Province FROM tblProvince"&gt;&lt;/asp:SqlDataSource&gt;
                      &lt;asp:SqlDataSource ID="SqlDataSource1" 
                      runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
                      SelectCommand="SELECT a.UserID, a.FirstName, a.LastName, a.UserName, a.Password, a.Birthdate, a.Address, a.Apt, a.City, a.Province, b.Province as 'ProvName',
                                      a.PostalCode, a.PhoneNum, a.Email, a.ynAdminUser
                                      FROM tblUser a
                                      INNER JOIN tblProvince B ON A.Province = B.ProvinceID
                                      WHERE (a.UserID = @UserID) AND (a.ynDelete = 0)"
                      InsertCommand="INSERT INTO tblUser(FirstName, LastName, UserName, Password, Birthdate, Address, Apt, City, Province, PostalCode, Email, PhoneNum, ynAdminUser, ynDelete) VALUES (@FirstName, @LastName, @UserName, @Password, @Birthdate, @Address, @Apt, @City, @Province, @PostalCode, @Email, @PhoneNum, @ynAdminUser, 0)"
                      UpdateCommand="UPDATE tblUser SET FirstName = @FirstName, LastName = @LastName, Birthdate = @Birthdate, Address = @Address, Apt = @Apt, City = @City, Province = @Province, PostalCode = @PostalCode, PhoneNum = @PhoneNum, Email = @Email, ynAdminUser = @ynAdminUser WHERE (UserID = @UserID)"&gt;
                      &lt;SelectParameters&gt;
                          &lt;asp:ControlParameter ControlID="gvUsers" Name="UserID" PropertyName="SelectedValue" Type="Int32" /&gt;
                      &lt;/SelectParameters&gt;
                      &lt;UpdateParameters&gt;
                          &lt;asp:Parameter Name="FirstName" Type="String" /&gt;
                          &lt;asp:Parameter Name="LastName" Type="String" /&gt;
                          &lt;asp:Parameter DbType="DateTime" Name="BirthDate" /&gt;
                          &lt;asp:Parameter Name="Address" Type="String" /&gt;
                          &lt;asp:Parameter Name="Apt" Type="String" /&gt;
                          &lt;asp:Parameter Name="City" Type="String" /&gt;
                          &lt;asp:ControlParameter Name="Province" ControlID="ddlProvince" PropertyName="SelectedValue" Type="Int32" /&gt;
                          &lt;asp:Parameter Name="PhoneNum" Type="String" /&gt;
                          &lt;asp:Parameter Name="Email" Type="String" /&gt;
                          &lt;asp:Parameter Name="ynAdminUser" Type="Boolean" /&gt;
                          &lt;asp:Parameter Name="UserID" Type="Int32" /&gt;
                      &lt;/UpdateParameters&gt;
                      &lt;InsertParameters&gt;
                          &lt;asp:Parameter Name="FirstName" Type="String" /&gt;
                          &lt;asp:Parameter Name="LastName" Type="String" /&gt;
                          &lt;asp:Parameter Name="UserName" Type="String" /&gt;
                          &lt;asp:Parameter Name="Password" Type="String" /&gt;
                          &lt;asp:Parameter DbType="DateTime" Name="Birthdate" /&gt;
                          &lt;asp:Parameter Name="Address" Type="String" /&gt;
                          &lt;asp:Parameter Name="Apt" Type="String" /&gt;
                          &lt;asp:Parameter Name="City" Type="String" /&gt;
                          &lt;asp:Parameter Name="Province" Type="Int32" /&gt;
                          &lt;asp:Parameter Name="PostalCode" Type="String" /&gt;
                          &lt;asp:Parameter Name="Email" Type="String" /&gt;
                          &lt;asp:Parameter Name="PhoneNum" Type="String" /&gt;
                          &lt;asp:Parameter Name="ynAdminUser" Type="Boolean" /&gt;
                      &lt;/InsertParameters&gt;
                  &lt;/asp:SqlDataSource&gt;
  </code></pre>