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;
}
}
}
代码有点长,解决了加分!
展开
 我来答
涛涛好物甄选
2014-04-19
知道答主
回答量:19
采纳率:0%
帮助的人:12.2万
展开全部
应该是GridView1.Rows[i].Cells[3].Text.ToString()转换为double时报错了,估计是你的GridView1.Rows[i].Cells[3].Text.ToString()中的值的格式无法转换为double类型,你可以设个断点调试一下,看一下其中的值
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式