using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

using Utilities;

 

namespace UserControls

{

    public partial class CustomUserControlExample1 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            DBConnect objDB = new DBConnect();

            int count = 0;

 

            objDB.GetDataSet("SELECT ProductNumber FROM Product", out count);

 

            // Create a Custom User Control (ASCX) object for each record in the dataset

            for (int recordNumber = 0; recordNumber < count; recordNumber++)

            {

                // Register the ASCX control with the page and typecast it to the appropriate class ProductDisplay

                ProductDisplay ctrl = (ProductDisplay)LoadControl("ProductDisplay.ascx");

 

                // Set properties for the ProductDisplay object

                ctrl.ProductID = (String)objDB.GetField("ProductNumber", recordNumber);

                ctrl.ProductImage = "images/" + ctrl.ProductID + ".jpg";

                ctrl.DataBind();

 

                // Add the control object to the WebForm's Controls collection

                Form.Controls.Add(ctrl);

            }

 

        }

    }

}