using System;
using System.Data;
using System.Data.SqlClient ;

using System.Configuration;
using System.Collections;
using System.Collections.Generic ;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DataList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       DataList1.DataSource = GetList(); 
       DataList1.DataBind();    
    }

    private List<Categories> GetList()
    {
        List<Categories> list = new List<Categories>();
        
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString);

        string mySql = "select * from Categories  ";
        SqlCommand myCommand = new SqlCommand(mySql, myConnection);

        myConnection.Open();
        SqlDataReader myReader = null;

        myReader = myCommand.ExecuteReader();

        while (myReader.Read())
        {
            Categories temp = new Categories((int)myReader["CategoryID"],
                                              (string)myReader["CategoryName"],
                                              (string)myReader["Description"]);
                                        //      (byte[])myReader["Picture"] );
            list.Add(temp); 
        }

        myReader.Close();
        myConnection.Close();

        return list;    
    }
}
