public Principal()
        {
            InitializeComponent();

            lc = new ListCars();

            for (int i = 0; i < _categories.Length; i++)
            {
                CategoriesCB.Items.Add(_categories[i]);
            }
        }
 public static void DeSerializeXml(string filePath, ref ListCars autoja)
 {
     XmlSerializer deserializer = new XmlSerializer(typeof(ListCars));
     try
     {
         FileStream xmlFile = new FileStream(filePath, FileMode.Open);
         autoja = (ListCars)deserializer.Deserialize(xmlFile);
         xmlFile.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
     }
 }
    private void initializeAll()
    {
        try
        {
            ListCars cars = new ListCars();
            Serialisointi.DeSerializeXml(Server.MapPath("~/App_Data/WanhatAutot.xml"), ref cars);
            Random random = new Random();
            List<Car> nelja = new List<Car>();

            while (nelja.Count < 4)
            {
                int rand = random.Next(0, cars.CarList.Count - 1);
                if (!nelja.Contains(cars.CarList.ElementAt(rand)))
                {
                    nelja.Add(cars.CarList.ElementAt(rand));
                }
            }
            Cars = cars.CarList;
            ViewState["AutotLista"] = Cars;
            List<string> merkit = new List<string>();
            merkit.Add("Kaikki");

            foreach (Car auto in cars.CarList)
            {
                string merkki = auto.Manufacturer;

                if (!merkit.Contains(merkki))
                {
                    merkit.Add(merkki);
                }
            }

            ListBox1.DataSource = merkit;
            ListBox1.DataBind();
            ListBox1.Height = 150;
            SortExpression = "DESC";
            loadListView(nelja);
        }
        catch (Exception ex)
        {
            er.InnerText = ex.Message;
        }
    }