How to make this DropDownList works inside the ListView?
<p>I have two tables in my database as following:</p>

<p><strong>Employee Table: Username, Name, Job, DivisonCode</strong></p>

<p><strong>Division Table: DivisionCode, DivisionName</strong></p>

<p>I am using ListView to show the information of the employee. Instead of showing the DivisionCode, I put a DropDownList that for showing the DivsionNames and of course I put this DropDownList inside the EditItemTemplate in the ListView. Everything works fine except editing the employee information. When I tried to change the division of the employee, I got the following error:</p>

<hr>

<blockquote>
  <p>Cannot insert the value NULL into column 'DivisionCode', table
  'psspdbTest.dbo.employee'; column does not allow nulls. UPDATE fails.
  The statement has been terminated.</p>
</blockquote>

<hr>

<p>My Code in ASP.NET:</p>

<pre><code>&lt;asp:ListView ID="ListView1" runat="server" DataKeyNames="Username" 
                DataSourceID="SqlDataSource1" InsertItemPosition="LastItem" &gt;

                &lt;AlternatingItemTemplate&gt;
                    &lt;tr style=""&gt;
                        &lt;td&gt;
                            &lt;asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                                Text="Delete" /&gt;
                            &lt;asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="NameLabel" runat="server" Text='&lt;%# Eval("Name") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="UsernameLabel" runat="server" Text='&lt;%# Eval("Username") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="JobTitleLabel" runat="server" Text='&lt;%# Eval("JobTitle") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="BadgeNoLabel" runat="server" 
                                Text='&lt;%# Eval("BadgeNo") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="EmpOrgTypeLabel" runat="server" 
                                Text='&lt;%# Eval("EmpOrgType") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="DivisionCodeLabel" runat="server" 
                                Text='&lt;%# Eval("DivisionCode") %&gt;' /&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/AlternatingItemTemplate&gt;

                &lt;EditItemTemplate&gt;
                    &lt;tr style=""&gt;
                        &lt;td&gt;
                            &lt;asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                                Text="Update" /&gt;
                            &lt;asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                                Text="Cancel" /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="NameTextBox" runat="server" Text='&lt;%# Bind("Name") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="UsernameLabel1" runat="server" Text='&lt;%# Eval("Username") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="JobTitleTextBox" runat="server" 
                                Text='&lt;%# Bind("JobTitle") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="BadgeNoTextBox" runat="server" Text='&lt;%# Bind("BadgeNo") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="EmpOrgTypeTextBox" runat="server" 
                                Text='&lt;%# Bind("EmpOrgType") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                                        DataSourceID="SqlDataSource1" DataTextField="DivisionName" 
                                        DataValueField="SapCode"&gt;
                                    &lt;/asp:DropDownList&gt;
                                    &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                        ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;" 
                                        DeleteCommand="DELETE FROM [Divisions] WHERE [SapCode] = @SapCode" 
                                        InsertCommand="INSERT INTO [Divisions] ([SapCode], [DivisionName]) VALUES (@SapCode, @DivisionName)" 
                                        SelectCommand="SELECT * FROM [Divisions]" 
                                        UpdateCommand="UPDATE [Divisions] SET [DivisionName] = @DivisionName WHERE [SapCode] = @SapCode"&gt;
                                        &lt;DeleteParameters&gt;
                                            &lt;asp:Parameter Name="SapCode" Type="Double" /&gt;
                                        &lt;/DeleteParameters&gt;
                                        &lt;InsertParameters&gt;
                                            &lt;asp:Parameter Name="SapCode" Type="Double" /&gt;
                                            &lt;asp:Parameter Name="DivisionName" Type="String" /&gt;
                                        &lt;/InsertParameters&gt;
                                        &lt;UpdateParameters&gt;
                                            &lt;asp:Parameter Name="DivisionName" Type="String" /&gt;
                                            &lt;asp:Parameter Name="SapCode" Type="Double" /&gt;
                                        &lt;/UpdateParameters&gt;
                                    &lt;/asp:SqlDataSource&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/EditItemTemplate&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;InsertItemTemplate&gt;
                    &lt;tr style=""&gt;
                        &lt;td&gt;
                            &lt;asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                                Text="Insert" /&gt;
                            &lt;asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                                Text="Clear" /&gt;
                        &lt;/td&gt;

                        &lt;td&gt;
                            &lt;asp:TextBox ID="NameTextBox" runat="server" Text='&lt;%# Bind("Name") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="UsernameTextBox" runat="server" 
                                Text='&lt;%# Bind("Username") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="JobTitleTextBox" runat="server" 
                                Text='&lt;%# Bind("JobTitle") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="BadgeNoTextBox" runat="server" Text='&lt;%# Bind("BadgeNo") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="EmpOrgTypeTextBox" runat="server" 
                                Text='&lt;%# Bind("EmpOrgType") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:TextBox ID="DivisionCodeTextBox" runat="server" 
                                Text='&lt;%# Bind("DivisionCode") %&gt;' /&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/InsertItemTemplate&gt;
                &lt;ItemTemplate&gt;
                    &lt;tr style=""&gt;
                        &lt;td&gt;
                            &lt;asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                                Text="Delete" /&gt;
                            &lt;asp:Button ID="EditButton" runat="server" CommandName="Edit" 
                                Text="Edit" /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="NameLabel" runat="server" Text='&lt;%# Eval("Name") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="UsernameLabel" runat="server" Text='&lt;%# Eval("Username") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="JobTitleLabel" runat="server" Text='&lt;%# Eval("JobTitle") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="BadgeNoLabel" runat="server" Text='&lt;%# Eval("BadgeNo") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="EmpOrgTypeLabel" runat="server" 
                                Text='&lt;%# Eval("EmpOrgType") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="DivisionCodeLabel" runat="server" 
                                Text='&lt;%# Eval("DivisionCode") %&gt;' /&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/ItemTemplate&gt;
                &lt;LayoutTemplate&gt;
                                &lt;table runat="server"&gt;
                                    &lt;tr runat="server"&gt;
                                        &lt;td runat="server"&gt;
                                            &lt;table ID="itemPlaceholderContainer" runat="server" border="0" 
                                                style=""&gt;
                                                &lt;tr runat="server" style=""&gt;
                                                    &lt;th runat="server"&gt;
                                                        &lt;/th&gt;
                                                    &lt;th runat="server"&gt;
                                                        Name&lt;/th&gt;
                                                    &lt;th runat="server"&gt;
                                                        Username&lt;/th&gt;
                                                    &lt;th runat="server"&gt;
                                                        JobTitle&lt;/th&gt;
                                                    &lt;th runat="server"&gt;
                                                        BadgeNo&lt;/th&gt;
                                                    &lt;th runat="server"&gt;
                                                        EmpOrgType&lt;/th&gt;
                                                    &lt;th runat="server"&gt;
                                                        DivisionCode&lt;/th&gt;
                                                &lt;/tr&gt;
                                                &lt;tr ID="itemPlaceholder" runat="server"&gt;
                                                &lt;/tr&gt;
                                            &lt;/table&gt;
                                        &lt;/td&gt;
                                    &lt;/tr&gt;
                                    &lt;tr runat="server"&gt;
                                        &lt;td runat="server" 
                                            style=""&gt;
                                            &lt;asp:DataPager ID="DataPager1" runat="server"&gt;
                                                &lt;Fields&gt;
                                                    &lt;asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                                        ShowLastPageButton="True" /&gt;
                                                &lt;/Fields&gt;
                                            &lt;/asp:DataPager&gt;
                                        &lt;/td&gt;
                                    &lt;/tr&gt;
                                &lt;/table&gt;
                &lt;/LayoutTemplate&gt;
                &lt;SelectedItemTemplate&gt;
                    &lt;tr style=""&gt;
                        &lt;td&gt;
                            &lt;asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                                Text="Delete" /&gt;
                            &lt;asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="NameLabel" runat="server" Text='&lt;%# Eval("Name") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="UsernameLabel" runat="server" Text='&lt;%# Eval("Username") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="JobTitleLabel" runat="server" Text='&lt;%# Eval("JobTitle") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="BadgeNoLabel" runat="server" 
                                Text='&lt;%# Eval("BadgeNo") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="EmpOrgTypeLabel" runat="server" 
                                Text='&lt;%# Eval("EmpOrgType") %&gt;' /&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;asp:Label ID="DivisionCodeLabel" runat="server" 
                                Text='&lt;%# Eval("DivisionCode") %&gt;' /&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/SelectedItemTemplate&gt;
            &lt;/asp:ListView&gt;

            &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;" 
                SelectCommand="SELECT     dbo.employee.Name, dbo.employee.Username, dbo.employee.JobTitle, dbo.employee.BadgeNo, dbo.employee.EmpOrgType, dbo.employee.DivisionCode
FROM         dbo.Divisions INNER JOIN
                      dbo.employee ON dbo.Divisions.SapCode = dbo.employee.DivisionCode" 
                DeleteCommand="DELETE FROM [employee] WHERE [Username] = @Username" 
                InsertCommand="INSERT INTO [employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (@Name, @Username, @JobTitle, @BadgeNo, @EmpOrgType, @DivisionCode)" 
                UpdateCommand="UPDATE [employee] SET [Name] = @Name, [JobTitle] = @JobTitle, [BadgeNo] = @BadgeNo, [EmpOrgType] = @EmpOrgType, [DivisionCode] = @DivisionCode WHERE [Username] = @Username"&gt;
                &lt;DeleteParameters&gt;
                    &lt;asp:Parameter Name="Username" Type="String" /&gt;
                &lt;/DeleteParameters&gt;
                &lt;InsertParameters&gt;
                    &lt;asp:Parameter Name="Name" Type="String" /&gt;
                    &lt;asp:Parameter Name="Username" Type="String" /&gt;
                    &lt;asp:Parameter Name="JobTitle" Type="String" /&gt;
                    &lt;asp:Parameter Name="BadgeNo" Type="Double" /&gt;
                    &lt;asp:Parameter Name="EmpOrgType" Type="Double" /&gt;
                    &lt;asp:Parameter Name="DivisionCode" Type="Double" /&gt;
                &lt;/InsertParameters&gt;
                &lt;UpdateParameters&gt;
                    &lt;asp:Parameter Name="Name" Type="String" /&gt;
                    &lt;asp:Parameter Name="JobTitle" Type="String" /&gt;
                    &lt;asp:Parameter Name="BadgeNo" Type="Double" /&gt;
                    &lt;asp:Parameter Name="EmpOrgType" Type="Double" /&gt;
                    &lt;asp:Parameter Name="DivisionCode" Type="Double" /&gt;
                    &lt;asp:Parameter Name="Username" Type="String" /&gt;
                &lt;/UpdateParameters&gt;
            &lt;/asp:SqlDataSource&gt;
</code></pre>

<p>So how to solve this problem?</p>
