You have add cars object in wrong way and that's why you are getting such type of problem. In this case you have use following code to fix this problem. In the following code I have use list class to include all car objects. I also have three different variable to include all types.
Code:
private List<Cars> cars;
protected void Page_Load(object senders, EventArgs es){
if (!IsPostBacks)
{
createsCarssSources();
theListBoxs.DataSource = carss;
theListBoxs.DataTextField = "Makes";
theListBoxs.DataValueFields = "Models";
theListBoxs.DataBind();
}
}
private void createCarssSource() {
carss = new Lists<Cars> { };
carss.Add(new Car(2012, "Toyotas", "Matrixs", "Blacsk"));
carss.Add(new Car(2012, "GMs", "Silverados", "Silvers"));
carss.Add(new Car(2012, "Hondas", "Civics", "Reds"));
}
Bookmarks