Aspx页面:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="electric.aspx.cs" Inherits="_1.electric" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
家电类<br />
<br />
<asp:Label ID="Label1" runat="server" Text="电视"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="40px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="冰箱"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="40px"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="洗衣机"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" Width="40px"></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="提交" />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="查看购物车" />
<br />
<br />
<asp:Table ID="Table1" runat="server"><!--table 在这儿-->
</asp:Table>
<br />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="修改" />
</div>
</form>
</body>
</html>
后台处理:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;namespace _1
{
public partial class electric : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["goods"] == null)
{
DataSet ds = new DataSet();
ds.Tables.Add("goods");
ds.Tables["goods"].Columns.Add("name");
ds.Tables["goods"].Columns.Add("count");
Session["goods"] = ds;
}
} protected void Button1_Click(object sender, EventArgs e)//显示购物车内容
{
DataSet ds = new DataSet();
ds = (DataSet)Session["goods"];
for (int i = 0; i < ds.Tables["goods"].Rows.Count; i++)
{
TableRow tr=new TableRow();
TableCell tc1=new TableCell();
TableCell tc2 = new TableCell();
TextBox tx1 = new TextBox();
TextBox tx2 = new TextBox();
tx1.Text = ds.Tables["goods"].Rows[i]["name"].ToString();
tx2.Text = ds.Tables["goods"].Rows[i]["count"].ToString();
tc1.Controls.Add(tx1);
tc2.Controls.Add(tx2);
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
Table1.Rows.Add(tr);
}
} protected void Button2_Click(object sender, EventArgs e)//添加商品
{
DataSet ds = new DataSet();
ds.Tables.Add("goods");
ds.Tables["goods"].Columns.Add("name");
ds.Tables["goods"].Columns.Add("count");
ds.Tables["goods"].Rows.Add(new object[] { Label1.Text, TextBox1.Text });
ds.Tables["goods"].Rows.Add(new object[] { Label2.Text, TextBox2.Text });
ds.Tables["goods"].Rows.Add(new object[] { Label3.Text, TextBox3.Text });
Session["goods"] = ds;
} protected void Button3_Click(object sender, EventArgs e)//修改
{
DataSet ds = new DataSet();
ds.Tables.Add("goods");
ds.Tables["goods"].Columns.Add("name");
ds.Tables["goods"].Columns.Add("count");
for (int i = 0; i <this.Table1.Rows.Count; i++)
{
Response.Write(Table1.Rows[i].Cells.Count+"------------");//为0啊啊啊啊 啊啊 啊啊 !!!
TextBox tb1=(TextBox)this.Table1.Rows[i].Cells[0].Controls[0];//??????????????????????????
TextBox tb2=(TextBox)Table1.Rows[i].Cells[0].Controls[1];
ds.Tables["goods"].Rows.Add(new object[] {tb1.Text , tb2.Text });
}
Session["goods"] = ds;
}
}
}
解决方案 »
- 新闻网首页怎么办?天天更新不累吗?
- 为什么asp.net的按钮默认就是重载呢?
- 初学者,真晕了
- 网上找到一个三级无刷新联动的例子,可惜怎么换成数据库都出错,请教各位
- UPDATE 语句的语法错误????? 在sql server里是正常的在access里就不对了,不懂
- C#操作word问题
- 关于在“类”中设置当前目录中Access数据库的路径?
- <----------请教System.Web.HttpContext.Current.Request.Files的问题------->
- 怎样得到站点的根路径(物理路径 和 URL路径)100分!
- 哪位能提供比较专业,比较酷的web登陆界面
- 求思路。。。。。。
- .net三层架构中Factory
过来拿分了 真不好意思