新的内容添加成功后如何向下一个页传值,急!!!
新闻添加页:add.aspx.cs
protected void btnADD_Click(object sender, EventArgs e)
{
type t = new type();
t.newsTitle = this.txtnewsTitle.Text;
t.newsText = this.txtnewsText.Text;
if (master.insertOperate(t))
{
txtnewsTitle.Text = " ";
txtnewsText.Text = " ";
Response.Redirect( "add-up.aspx ");
}
else
{
Response.Write( "添加失败! ");
}
接收页:add-up.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = DB.createCon();
con.Open();
string strID = Request.Form.Get( "newsID ").ToString();
SqlCommand cmd = new SqlCommand( "select * from newsMaster where newsID= ' " + strID + " ' ", con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
this.Label1.Text = dr[ "newsTitle "].ToString();
this.Label2.Text = dr[ "newsText "].ToString();
dr.Close();
}
新闻主键:newsID
新闻标题:newsTitle
新闻内容:newsText
要实现,在add.aspx添加成功后,跳转到add-up.aspx后,add-up.aspx要能接受到刚才添加成功的那一列的内容.(注:不是用session保存,因为要获得刚才添加成功后的那一列的主键.)
上面我写的add-up.aspx.cs的代码是不对的,哪位能帮我写个正确的,必当感激不尽.
------解决方案--------------------add.aspx.cs
Response.Redirect( "add-up.aspx?newsID=1&newsTitle=2&newsText=3 ");
add-up.aspx.cs
string newsID = Request.Params[ "newsID "];
string newsTitle= Request.Params[ "newsTitle "];
string newsText= Request.Params[ "newsText "];
------解决方案--------------------用传参 然后用me.request.query( "查询条件的主键 ")取得主键 然后通过SQL语句就可以查到所有的值了!!