ASP.Net DetailsView DropDownList data does not get updated in the database

theboss77

New Member
On an ASP.Net web form, there are several TextBoxes and 2 DropDownLists. One of these DropDownLists is not working as expected. If the user changes the displayed value in the DropDownList, the changed value is not saved back to the database. The user can insert data into the database with the same DropDownList without any issues. The only way currently to change the value is to delete the row of data and re-inserting it with the new value from the DropDownList.When the data is saved back to the database all changes to the other DropDownList and all other controls on the form are saved except for the "Class" DropDownList. Can you look at our coding and spot where we made an error?This is the markup of the working DropDownList:\[code\] <asp:TemplateField HeaderText="Student:" SortExpression="StudentID"> <EditItemTemplate> <asp:DropDownList ID="DropDownListStudent" Runat="server" DataSourceID="SqlDataSourceStudents" DataTextField = "StudentName" DataValueField="ID" SelectedValue='http://stackoverflow.com/questions/15816149/<%# Bind("StudentID") %>' ForeColor="Blue"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidatorEditStudent" runat="server" ControlToValidate="DropDownListStudent" ErrorMessage="Please select a Student here." Font-Bold="True" Font-Italic="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic"> </asp:RequiredFieldValidator> </EditItemTemplate> <InsertItemTemplate> <asp:DropDownList ID="DropDownListStudent" Runat="server" DataSourceID="SqlDataSourceStudents" DataTextField = "StudentName" DataValueField="ID" SelectedValue='http://stackoverflow.com/questions/15816149/<%# Bind("StudentID") %>' ForeColor="Blue"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidatorInsertStudent" runat="server" ControlToValidate="DropDownListStudent" ErrorMessage="Please select a Student here." Font-Bold="True" Font-Italic="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic"> </asp:RequiredFieldValidator> </InsertItemTemplate> <ItemTemplate> <asp:DropDownList ID="DropDownListStudent" Runat="server" DataSourceID="SqlDataSourceStudents" DataTextField = "StudentName" DataValueField="ID" SelectedValue='http://stackoverflow.com/questions/15816149/<%# Bind("StudentID") %>' Enabled="false" ForeColor="Blue" Font-Bold="true"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField>\[/code\]This is the markup for the DropDownList that's not working:\[code\] <asp:TemplateField HeaderText="Class:" SortExpression="ClassID"> <EditItemTemplate> <asp:DropDownList ID="DropDownListClassEdit" Runat="server" DataSourceID="SqlDataSourceClasses" DataTextField = "ClassName" DataValueField="ID" SelectedValue='http://stackoverflow.com/questions/15816149/<%# Bind("ClassID") %>' ForeColor="Blue"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidatorEditClass" runat="server" ControlToValidate="DropDownListClassEdit" ErrorMessage="Please select a Class here." Font-Bold="True" Font-Italic="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic"> </asp:RequiredFieldValidator> </EditItemTemplate> <InsertItemTemplate> <asp:DropDownList ID="DropDownListClassInsert" Runat="server" DataSourceID="SqlDataSourceClasses" DataTextField = "ClassName" DataValueField="ID" SelectedValue='http://stackoverflow.com/questions/15816149/<%# Bind("ClassID") %>' AppendDataBoundItems="True" ForeColor="Blue" OnDataBinding="DropDownListClassInsert_DataBinding"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidatorInsertClass" runat="server" ControlToValidate="DropDownListClassInsert" ErrorMessage="Please select a Class here." Font-Bold="True" Font-Italic="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic"> </asp:RequiredFieldValidator> </InsertItemTemplate> <ItemTemplate> <asp:DropDownList ID="DropDownListClass" Runat="server" DataSourceID="SqlDataSourceClasses" DataTextField = "ClassName" DataValueField="ID" SelectedValue='http://stackoverflow.com/questions/15816149/<%# Bind("ClassID") %>' Enabled="false" ForeColor="Blue" Font-Bold="true"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField>\[/code\]This is the DataSource for the working DropDownList:\[code\]<asp:SqlDataSource ID="SqlDataSourceStudents" runat="server" ConnectionString="<%$ ConnectionStrings:Knowledge Academy %>" SelectCommand= "SELECT NULL AS ID, NULL AS StudentName UNION SELECT ID, Surname + ', ' + Forename AS StudentName FROM StudentsORDER BY 2"></asp:SqlDataSource>\[/code\]This is the DataSource for the DropDownList that's not working:\[code\]<asp:SqlDataSource ID="SqlDataSourceClasses" runat="server" ConnectionString="<%$ ConnectionStrings:Knowledge Academy %>" SelectCommand= "SELECT NULL AS ID, NULL AS ClassName, NULL AS Grade UNION SELECT ID, ClassName + ' *** Grade: ' + Grade AS ClassName, Grade FROM Classes ORDER BY 2, 3"></asp:SqlDataSource>\[/code\]
 
Back
Top