ASP.NET Assignment 2 Problem

June 11, 2012    ASP.NET blog school

Had an error while working on my second assignment for ASP.NET class. For this assignment I had to make a web page that shows a drop down list of car model, which when selected shows a list of checkbox items for car packages. It will output what they selected once the user selects the car packages and presses submit.

 

Problem:

Car model website does not receive check box list items for drop down list items other than the first item. For example: it will only show for the options for Nissan Maxima because it is the first car model in the list, if the user selects any other car models it does not work.

 

 

 

Impact: User cannot see the specific options for each car model when they select it.


Solution:

if (!Page.IsPostBack) {
  ddlModels.DataSource = ModelsList;
  ddlModels.DataBind();
}

This code makes it so that the data source does not reset to the first item if the page does not

refresh, therefore allowing the correct options to be displayed.