修改
在a.aspx有Label控件显示的信息,下面有个修改按钮,单击修改后a.aspx的值传到b.aspx页的textbox控件,修改后保存到gridview --------------------编程问答-------------------- 传值,然后update方法 --------------------编程问答-------------------- 我之前告诉你的链接,你看了? --------------------编程问答-------------------- 看了,不是很懂,新手,体谅 --------------------编程问答-------------------- 那里不会 --------------------编程问答-------------------- 一个页面我使用Session["KHMC"] = Label1.Text;Session["KHJB"] = Label3.Text;
传值
另一个页面用if (Session["KHMC"] != null)
{
TextBox1.Text = Session["KHMC"].ToString();
}
if (Session["KHJB"] != null)
{
DropDownList2.Text = Session["KHJB"].ToString();
}
接受
我不知道怎么把接受的值修改后替换数据库原有的值 --------------------编程问答-------------------- 两个页面之间有关系么? 比如 A用 window.open 打开了 B
还是它们之间进行跳转.
因为使用Session 不是一个好的方案.基础打好 会少走很多不必要的弯路. --------------------编程问答-------------------- Response.Redirect("kehuxiugai.aspx");我使用这个跳转 --------------------编程问答-------------------- 就是我在A页面的按钮里写了sqlcon.Open();
string sqlstr = "select * from QZKHB";
SqlDataAdapter da = new SqlDataAdapter(sqlstr, sqlcon);
DataSet ds = new DataSet();
da.Fill(ds, "QZKHB");
Session["KHMC"] = Label1.Text;
Session["KHJB"] = Label3.Text;
Response.Redirect("kehuxiugai.aspx");
在B页面写了protected void Page_Load(object sender, EventArgs e)
{
if (Session["KHMC"] != null)
{
TextBox1.Text = Session["KHMC"].ToString();
}
if (Session["KHJB"] != null)
{
DropDownList2.Text = Session["KHJB"].ToString();
}
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=Company;Integrated Security=True;Pooling=False");
con.Open();
string SqlStr = "update QZKHB set KHMC='" + TextBox1.Text + "',KHJB= '" + DropDownList2.Text + "'";
SqlCommand com = new SqlCommand(SqlStr, con);
com.ExecuteNonQuery();
SqlDataAdapter ada = new SqlDataAdapter("select * from QZKHB", con);
DataSet ds = new DataSet();
ada.Fill(ds);
con.Close();
Response.Redirect("qzkhliebiao.aspx");
}
结果修改了没变化 --------------------编程问答-------------------- 可以使用 post 方式传参的
参考 asp.net 中 使用post方式页面传递多个值的例子
http://blog.csdn.net/sandy945/article/details/5437964
不过 这不是现在问题的原因,只是这种方式要比Session要好一些. 等你之后可以看下.
你的问题是要替换数据库原有的值是把, 你需要找到主键或者对应的标示 来进行数据的更新. --------------------编程问答-------------------- 嗯,好,谢谢! --------------------编程问答-------------------- if (Session["KHJB"] != null)
{
DropDownList2.Text = Session["KHJB"].ToString();
}
=>
if (Session["KHJB"] != null)
{
//要保证DropDownList2绑定了数据
ListItem item = DropDownList2.Items.FindByText(Session["KHJB"].ToString());
if(item!=null)
item.Selected = true;
}
--------------------编程问答-------------------- SqlDataAdapter ada = new SqlDataAdapter("select * from QZKHB", con);
DataSet ds = new DataSet();
ada.Fill(ds);
con.Close();
Response.Redirect("qzkhliebiao.aspx");
=>
con.Close();
Response.Redirect("qzkhliebiao.aspx");
--------------------编程问答-------------------- 需要刷新把
补充:.NET技术 , C#