ASP.NET字符串格式问题
publicpartialclasscart:System.Web.UI.Page{privatestaticstringcartid;privatestaticstri...
public partial class cart : System.Web.UI.Page
{
private static string cartid;
private static string shopperid;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(checkcart())
{
DataSet ds = databaseAccess.Getcart(cartid);
GridView1.DataSource = ds;
GridView1.DataBind();
double totalmoney = 0;
double tempprice;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
tempprice = Convert.ToDouble(GridView1.Rows[i].Cells[3].Text.ToString());
totalmoney += tempprice;
}
Label1.Text = totalmoney.ToString();
}
else
{
Response.Write("<script language='javascript'>alert('您的够物车为空!')</script>");
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int productID = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
string sql = "delete from shoppingcart where cartID='" + cartid + "' and productID='" + productID + "'";
databaseAccess.ExeSql(sql);
cartid = Request.Cookies["cartID"].Value.ToString().Trim();
DataSet ds = databaseAccess.Getcart(cartid);
GridView1.DataSource = ds;
GridView1.DataBind();
double totalmoney = 0;
double tempprice;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
tempprice = Convert.ToDouble(GridView1.Rows[i].Cells[3].Text.ToString());
totalmoney += tempprice;
}
Label1.Text = totalmoney.ToString();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
cartid = Request.Cookies["cartID"].Value.ToString().Trim();
shopperid =Request.Cookies["userName"].Value.ToString();
string sql = string.Format("insert into orders(cartID,shopperID,totalcost) values({0},{1},convert(money,{2}))",cartid ,"'"+shopperid+"'" ,Label1 .Text );
databaseAccess.ExeSql(sql);
Response.Cookies.Clear();
Response.Redirect("order.aspx");
}
private bool checkcart()
{
try
{
cartid = Request.Cookies["cartID"].Value.ToString().Trim();
return true;
}
catch
{
return false;
}
}
}
代码有点长,解决了加分! 展开
{
private static string cartid;
private static string shopperid;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(checkcart())
{
DataSet ds = databaseAccess.Getcart(cartid);
GridView1.DataSource = ds;
GridView1.DataBind();
double totalmoney = 0;
double tempprice;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
tempprice = Convert.ToDouble(GridView1.Rows[i].Cells[3].Text.ToString());
totalmoney += tempprice;
}
Label1.Text = totalmoney.ToString();
}
else
{
Response.Write("<script language='javascript'>alert('您的够物车为空!')</script>");
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int productID = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
string sql = "delete from shoppingcart where cartID='" + cartid + "' and productID='" + productID + "'";
databaseAccess.ExeSql(sql);
cartid = Request.Cookies["cartID"].Value.ToString().Trim();
DataSet ds = databaseAccess.Getcart(cartid);
GridView1.DataSource = ds;
GridView1.DataBind();
double totalmoney = 0;
double tempprice;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
tempprice = Convert.ToDouble(GridView1.Rows[i].Cells[3].Text.ToString());
totalmoney += tempprice;
}
Label1.Text = totalmoney.ToString();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
cartid = Request.Cookies["cartID"].Value.ToString().Trim();
shopperid =Request.Cookies["userName"].Value.ToString();
string sql = string.Format("insert into orders(cartID,shopperID,totalcost) values({0},{1},convert(money,{2}))",cartid ,"'"+shopperid+"'" ,Label1 .Text );
databaseAccess.ExeSql(sql);
Response.Cookies.Clear();
Response.Redirect("order.aspx");
}
private bool checkcart()
{
try
{
cartid = Request.Cookies["cartID"].Value.ToString().Trim();
return true;
}
catch
{
return false;
}
}
}
代码有点长,解决了加分! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询