首页 新闻 会员 周边

asp.net页面A.aspx传数据到B.aspx显示?

0
悬赏园豆:30 [已解决问题] 解决于 2013-05-04 12:16

本人是新手,做的是维护别人开发过的系统,主要是添加或修改一些功能。求高手指点下....

A.aspx页面里有textbox和GridView(里面有TextBox选项),B.aspx页面有Label和GridView显示A页面传过来的数据。点击按钮Button后,怎么把A.aspx的所有数据传到B.aspx页面来显示? B页面点击修改按钮后,又返回先前的页面并保存原选择好的数据。

 A.aspx页面 -----------------------------------------------------------------------------

B.aspx页面------------------------------------------------------------------------------

 

A.aspx页面...CustomerTlww
public partial class CustomerTlww : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//加截StockOut
if (!IsPostBack)
{
if (Request["ID"] != null)
{
string sql = ConfigurationManager.ConnectionStrings["ty2010ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sql);
conn.Open();
SqlCommand command = new SqlCommand("getStockOutByID", conn);//存储过程
command.CommandType = CommandType.StoredProcedure;
SqlParameter spID = new SqlParameter("ID", SqlDbType.UniqueIdentifier);
spID.Value = new Guid(Request["ID"]);
command.Parameters.Add(spID);
SqlDataReader sdr = command.ExecuteReader();
if (sdr.Read())
{
txtName.Text = sdr["name"].ToString();
txtCustomerName.Text = sdr["CustomerName"].ToString();
txtCustomerTel.Text = sdr["CustomerTel"].ToString();
txtCustomerAddress.Text = sdr["CustomerAddress"].ToString();
txtMemo.Text = sdr["memo"].ToString();
txtPreparer.Text = sdr["Preparer"].ToString();
txtFinanceOfficer.Text = sdr["FinanceOfficer"].ToString();
txtTallyman.Text = sdr["Tallyman"].ToString();
txtAddTime.Text = string.Format("{0:yyyy-MM-dd}", sdr["addtime"]);
txtConsignee.Text = sdr["Consignee"].ToString();
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql = ConfigurationManager.ConnectionStrings["ty2010ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sql);
//定义一个事务
SqlTransaction tran = null;
bool s = false;
try
{
conn.Open();
tran = conn.BeginTransaction();
Guid stockOutID;
if (Request["ID"] != null)
{
stockOutID = new Guid(Request["ID"]);
}
else
{
stockOutID = Guid.NewGuid();
}
SaveStockOut(conn, tran, stockOutID);

foreach (ListViewDataItem lvdt in ListView1.Items)
{
GridView gv = (GridView)lvdt.FindControl("GridView1");
foreach (GridViewRow gvr in gv.Rows)
{
TextBox amount = (TextBox)gvr.FindControl("TextBoxAmount");
HiddenField hidIsUsing = (HiddenField)gvr.FindControl("hidIsUsing");
if (amount.Text != "" || hidIsUsing.Value == "True")
{
SaveStockOutDetail(conn, tran, stockOutID, gvr);
}
}
}
tran.Commit();
s = true;
}
catch (Exception ex)
{
//回滚
tran.Rollback();
Response.Write(ex.StackTrace + ex.Source + ex.Message);
}
finally
{
conn.Close();
}
if (s)
{
Response.Redirect("DisplayStockOutNew.aspx");//问题指的是跳转到B.aspx页面
}
Response.Write("<script>javascript:alert('添加成功!!!');</script>");
}
private void SaveStockOutDetail(SqlConnection conn, SqlTransaction tran, Guid stockOutID, GridViewRow gvr)
{
SqlCommand command = new SqlCommand("SaveStockOutDetail", conn, tran);
command.CommandType = CommandType.StoredProcedure;

Label lableID = (Label)gvr.FindControl("LabelID");
Label lableProductID = (Label)gvr.FindControl("LabelProductID");
decimal price = Convert.ToDecimal(((TextBox)gvr.FindControl("TextBoxPrice")).Text);
TextBox txtAmount = (TextBox)gvr.FindControl("TextBoxAmount");
TextBox txtSpecification = (TextBox)gvr.FindControl("TextBoxSpecification");
TextBox txtMemo = (TextBox)gvr.FindControl("TextBoxMemo");
HiddenField hidIsUsing = (HiddenField)gvr.FindControl("hidIsUsing");

SqlParameter spID = new SqlParameter("ID", SqlDbType.UniqueIdentifier);
SqlParameter spStockOutID = new SqlParameter("StockOutID", SqlDbType.UniqueIdentifier);
SqlParameter spProductID = new SqlParameter("ProductID", SqlDbType.UniqueIdentifier);
SqlParameter spAmount = new SqlParameter("amount", SqlDbType.Decimal);
SqlParameter spPrice = new SqlParameter("price", SqlDbType.Decimal);
SqlParameter spSpecification = new SqlParameter("specification", SqlDbType.NVarChar);
SqlParameter spMemo = new SqlParameter("memo", SqlDbType.NVarChar);
SqlParameter spIsUsing = new SqlParameter("IsUsing", SqlDbType.Bit);

if (lableID.Text == "")
{
spID.Value = Guid.NewGuid();
}
else
{
spID.Value = new Guid(lableID.Text);
}
spStockOutID.Value = stockOutID;
spProductID.Value = new Guid(lableProductID.Text);
if (txtAmount.Text != "")
{
spAmount.Value = Convert.ToDecimal(txtAmount.Text);
}
else
{
spAmount.Value = 0;
}
spPrice.Value = price;
spSpecification.Value = txtSpecification.Text;
spMemo.Value = txtMemo.Text;

if (txtAmount.Text != "")
{
spIsUsing.Value = 1;
}
else if (hidIsUsing.Value == "True")
{
spIsUsing.Value = 0;
}

command.Parameters.Add(spID);
command.Parameters.Add(spStockOutID);
command.Parameters.Add(spProductID);
command.Parameters.Add(spAmount);
command.Parameters.Add(spPrice);
command.Parameters.Add(spSpecification);
command.Parameters.Add(spMemo);
command.Parameters.Add(spIsUsing);
command.ExecuteNonQuery();
}
private void SaveStockOut(SqlConnection conn, SqlTransaction tran, Guid stockOutID)
{
SqlCommand command = new SqlCommand("SaveStockOut", conn, tran);
command.CommandType = CommandType.StoredProcedure;

SqlParameter spID = new SqlParameter("ID", SqlDbType.UniqueIdentifier);
SqlParameter spName = new SqlParameter("name", SqlDbType.NVarChar);
SqlParameter spCustomerName = new SqlParameter("CustomerName", SqlDbType.NVarChar);
SqlParameter spCustomerTel = new SqlParameter("CustomerTel", SqlDbType.NVarChar);
SqlParameter spCustomerAddress = new SqlParameter("CustomerAddress", SqlDbType.NVarChar);
SqlParameter spSalesman = new SqlParameter("Salesman", SqlDbType.NVarChar);
SqlParameter spFinanceOfficer = new SqlParameter("FinanceOfficer", SqlDbType.NVarChar);
SqlParameter spPreparer = new SqlParameter("Preparer", SqlDbType.NVarChar);
SqlParameter spTallyman = new SqlParameter("Tallyman", SqlDbType.NVarChar);
SqlParameter spMemo = new SqlParameter("Memo", SqlDbType.NVarChar);
SqlParameter spConsignee = new SqlParameter("Consignee", SqlDbType.NVarChar);
SqlParameter spAddtime = new SqlParameter("addtime", SqlDbType.DateTime);
SqlParameter spUserID = new SqlParameter("UserID", SqlDbType.UniqueIdentifier);

spID.Value = stockOutID;
spName.Value = txtName.Text;
spCustomerName.Value = txtCustomerName.Text;
spCustomerTel.Value = txtCustomerTel.Text;
spCustomerAddress.Value = txtCustomerAddress.Text;
spSalesman.Value = "";
spFinanceOfficer.Value = txtFinanceOfficer.Text;
spPreparer.Value = txtPreparer.Text;
spTallyman.Value = txtTallyman.Text;
spMemo.Value = txtMemo.Text;
spConsignee.Value = txtConsignee.Text;
spAddtime.Value = Convert.ToDateTime(txtAddTime.Text);
spUserID.Value = new Guid(Session["userID"].ToString());

command.Parameters.Add(spID);
command.Parameters.Add(spUserID);
command.Parameters.Add(spName);
command.Parameters.Add(spCustomerName);
command.Parameters.Add(spCustomerTel);
command.Parameters.Add(spCustomerAddress);
command.Parameters.Add(spSalesman);
command.Parameters.Add(spFinanceOfficer);
command.Parameters.Add(spPreparer);
command.Parameters.Add(spTallyman);
command.Parameters.Add(spMemo);
command.Parameters.Add(spAddtime);
command.Parameters.Add(spConsignee);

command.ExecuteNonQuery();
}
protected void DropDownListBrand_SelectedIndexChanged(object sender, EventArgs e)
{
ListView1.DataBind();
}
}
-----------------------------------------------------------------------------------
B.aspx页面--DisplayStockOutNew
public partial class DisplayStockOutNew : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//加截StockOut
if (!IsPostBack)
{
if (Request["ID"] != null)
{
string sql = ConfigurationManager.ConnectionStrings["ty2010ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sql);
conn.Open();
SqlCommand command = new SqlCommand("getStockOutByID", conn);
command.CommandType = CommandType.StoredProcedure;
SqlParameter spID = new SqlParameter("ID", SqlDbType.UniqueIdentifier);
spID.Value = new Guid(Request["ID"]);
command.Parameters.Add(spID);
SqlDataReader sdr = command.ExecuteReader();
if (sdr.Read())
{
txtAddtime.Text = string.Format("{0:yyyy-MM-dd}", sdr["addtime"]);
txtName.Text = sdr["name"].ToString();
txtCustomerName.Text = sdr["CustomerName"].ToString();
txtCustomerTel.Text = sdr["CustomerTel"].ToString();
txtCustomerAddress.Text = sdr["CustomerAddress"].ToString();
txtMemo.Text = sdr["memo"].ToString().Replace("\n", "<br/>");
txtPreparer.Text = sdr["Preparer"].ToString();
txtFinanceOfficer.Text = sdr["FinanceOfficer"].ToString();
txtTallyman.Text = sdr["Tallyman"].ToString();
txtConsignee.Text = sdr["consignee"].ToString();
txtSum.Text = string.Format("{0:F0}", sdr["Sum"]);
}
}
}
}
}

 

lqps的主页 lqps | 初学一级 | 园豆:44
提问于:2012-02-06 12:20
< >
分享
最佳答案
1

在A页面你提交订单的时候,就把所有数据存到数据库中,然后把订单的编号传到B页面,在B页面的Page_load事件中就读取传过来的订单编号,然后从数据库查询到订单的详细数据显示在界面上。怎么传值到B页面就别问了,方法很多,给你个网址http://www.cnblogs.com/shengtianlong/archive/2010/08/11/1797608.html

B上点修改时同理把订单编号传到A,在A页面上显示数据就行了。

 

看了一眼你上面的代码,好像就是这样实现的啊。只是你打开B界面时应该把ID传过去,这样写,

Response.Redirect("DisplayStockOutNew.aspx?ID="+你要传的编号);//问题指的是跳转到B.aspx页面
收获园豆:30
LCM | 大侠五级 |园豆:6876 | 2012-02-06 13:38

谢谢LCM,就是不怎么清楚传值呢?

lqps | 园豆:44 (初学一级) | 2012-02-06 14:55

@lqps: 不清楚传值,我上面说过了啊,

Response.Redirect("DisplayStockOutNew.aspx?ID="+你要传的编号);
上面这句话就是把你要传的编号传到新的页面。在新的页面用Request.QueryString["ID"]或
Request["ID"]
就能获取到值的。
LCM | 园豆:6876 (大侠五级) | 2012-02-06 14:58

@lqps: 并且我上面回复中的网址,你进去看一下,里面有很多种传值方式,都可以传值的。看你的代码,应该是用里面的第一种。

LCM | 园豆:6876 (大侠五级) | 2012-02-06 14:59

@LCM: 虽然还是不太明白,不过还是非常感谢LCM,之前有过的问题也是LCM解决的.

lqps | 园豆:44 (初学一级) | 2012-02-06 17:30
其他回答(2)
1

楼主维护的代码应该写的有些年头了。。。

Localhost | 园豆:443 (菜鸟二级) | 2012-02-06 15:40
0

http://q.cnblogs.com/q/31632/

慧☆星 | 园豆:5640 (大侠五级) | 2012-02-07 09:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册