public partial class Desktops : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable mydt = new DataTable();
DataRow myrow;
mydt.Columns.Add("Product Name");
mydt.Columns.Add("Price");
Session["MyDataTable"] = mydt;
}
}
protected voidDetailsView1_ItemCommand(object sender,DetailsViewCommandEventArgs e) {
if (e.CommandName == "save")
{
ArrayList FavD = (ArrayList)Session["FavDesktops"];
if (FavD == null)
{
FavD = new ArrayList();
}
FavD.Add(DetailsView1.Rows[2].Cells[1].Text);
FavD.Add(DetailsView1.Rows[7].Cells[1].Text);
Session["FavDesktops"] = FavD;
DataTable t = (DataTable)Session["MyDataTable"];
DataRow myrow = t.NewRow();
myrow = t.NewRow();
myrow["Product Name"] = FavD[0].ToString();
myrow["Price"] = FavD[1].ToString();
t.Rows.Add(myrow);
t.AcceptChanges();
Session["MyDataTable"] = t;
GridView2.DataSource = t;
GridView2.DataBind();
}
}
protected void Page_PreRender(objectsender, EventArge)
{
string sFavsHTML = "<p>You are considering the following desktops:</p><p><b>";
ArrayList alFavorites = (ArrayList)Session["FavDesktops"];
if (alFavorites != null)
{
foreach (string sItem inalFavorites)
{
sFavsHTML += sItem +"<br />";
}
}
else
{
sFavsHTML += "None";
}
sFavsHTML += "</b></p>";
lblconsidering.Text = sFavsHTML;
}
}