(3) 这是购物车页面的代码,请各位老兄帮忙看一下有没有错误啊,我点击了购买安钮后,购物车页面无数据显示。我是用
DataList里面放上Label作的。
public partial class foremanage_shopcar : System.Web.UI.Page
{
    public SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"]);
    public string insertsql;
    private double total; //总购物金额
    protected void Page_Load(object sender, EventArgs e)
    {
        
        try
        {
            total = 0;
            if (Class2.godset.Tables[0].Rows.Count > 0)
            {
                DataList1.DataSource = Class2.godset;
                DataList1.DataBind();            }
            else
            {            }
        }
        catch
        {        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Class2.godset.Clear();     //清空数据集
        Session["bus"] = null;
        Response.Redirect("shopcar.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        strcon.Open(); //打开数据连接
        try
        {
            insertsql = "insert into tb_mainorder(username,paytype,carrytype,orderdate,perform,res) values('" + Session["username"].ToString() + "','" + ddlpay.Text.ToString() + "','" + ddlmail.Text.ToString() + "','" + System.DateTime.Now + "','" + 0 + "','" + txtres.Text.ToString() + "')";
            SqlCommand commz = strcon.CreateCommand();
            commz.CommandText = insertsql; //插入主表信息
            commz.ExecuteNonQuery();
            Int64 orderid = 0;
            SqlDataAdapter adamax = new SqlDataAdapter("select max(mainorderid) as ordmax from tb_mainorder", strcon);
            DataSet maxds = new DataSet();
            adamax.Fill(maxds);
            DataRow[] rows = maxds.Tables[0].Select();
            foreach (DataRow row in rows)
            { orderid = Convert.ToInt64(row["ordmax"]); }
            for (int i = 0; i < ((Hashtable)(Session["bus"])).Count; i++)
            {
                Int32 goodsid = Convert.ToInt32(((Label)DataList1.Items[i].FindControl("id")).Text);
                Double price = Convert.ToDouble(((Label)DataList1.Items[i].FindControl("total")).Text);
                int number = Convert.ToInt32(((Label)DataList1.Items[i].FindControl("count")).Text);
                insertsql = "insert into tb_orderdetail (mainorderid,goodsid,price,number) values('" + orderid + "','" + goodsid + "','" + price + "','" + number + "')";
                //明细表信息插入
                commz.CommandText = insertsql;
                commz.ExecuteNonQuery();
            }
        }
        catch
        {
        }
        finally
        {
            Class2.godset.Clear();     //清空数据集
            Session["bus"] = null;
            Response.Redirect("shopcar.aspx");
        }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        int id = e.Item.ItemIndex;   //添加页眉页脚时会产生索引值-1
        if (id >= 0)
        {
            DataRow[] rows = Class2.godset.Tables[0].Select();
            foreach (DataRow row in rows)
            {
                if (row["id"].ToString() == ((Label)e.Item.FindControl("id")).Text.ToString())
                {
                    ((Label)e.Item.FindControl("count")).Text = ((Hashtable)(Session["bus"]))[row["id"].ToString()].ToString();
                }
            }
            ((Label)e.Item.FindControl("total")).Text = (Convert.ToDouble(((Label)e.Item.FindControl("goodsval")).Text) * Convert.ToInt64(((Label)e.Item.FindControl("count")).Text)).ToString() + (Convert.ToDouble(((Label)e.Item.FindControl("youhui")).Text) * Convert.ToInt64(((Label)e.Item.FindControl("count")).Text)).ToString();
            total = total + Convert.ToDouble(((Label)e.Item.FindControl("total")).Text);
            Label1.Text = "总计:" + total.ToString();
        }
    }
    protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {    }
}