RandomProducts.ascx

 

 

Similar to the Recentadditions.ascx this too is a user control having a DataList and image and label in its Item Template.This user control generates a random product each time the browser is refreshed.

 

Source code is here

 

 

private void Page_Load(object sender, System.EventArgs e)

              {

                     SqlConnection objcon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

                     string sql ="Select top 1 im.imagename,pr.productid,pr.modelname from products pr,images im where pr.productid= im.productid order by newid()";            // Generate Random products each time the browser is refreshed.

                     SqlDataAdapter objda = new SqlDataAdapter(sql,objcon);

                     DataSet ds = new DataSet();

                     objda.Fill(ds);

                     dsRandomList.DataSource = ds;

                     dsRandomList.DataBind();

              }

 

Back to main page