注册 登录
编程论坛 ASP.NET技术论坛

[求助]关于取TextBox值的问题

ice_beiyu 发布于 2007-09-12 12:06, 672 次点击

现在页面上有一个TextBox和一个确定按钮,TextBox初始值是数据库茶来的一个值,想在TextBox内对其进行修改,修改后再保存到数据库,可是现在保存的却是原来的值,而不是修改后的。

代码如下:请各位高手指点迷津。
protected void Page_Load(object sender, EventArgs e)
{

id = Request.QueryString["Tcbh"];
yd = Request.QueryString["pyyd"];
Session["xid"] = id;
Session["xyd"] = yd;

string xid = (string)Session["xid"];
string xyd = (string)Session["xyd"];
db = new DBAccess();
sql1 = "select ydjh from ydpy where Tcbh='" + id + "' and pyyd='" + yd + "'";
DataSet dv1 = db.executeQuery(sql1);
if (dv1.Tables[0].Rows.Count > 0)
{
str1 = dv1.Tables[0].Rows[0]["ydjh"].ToString();
TextBox1.Text = str1;
}


}
protected void Button1_Click(object sender, EventArgs e)
{
str2 = TextBox1.Text;
db = new DBAccess();
sql2 = "update ydpy set ydjh='" + str2 + "' where Tcbh='" + id + "' and pyyd='" + yd + "'";
Response.Write(sql2);
Response.End();
isok = db.executeUpdate(sql2);

if (isok == true)
{
TextBox1.Text = "";
Function.printJS(Response, "alert(\"修改成功!\");window.parent.close();");
}
}

3 回复
#2
师妃暄2007-09-12 12:33

protected void Page_Load(object sender, EventArgs e)
{
if(!Ispostback)
{

id = Request.QueryString["Tcbh"];
yd = Request.QueryString["pyyd"];
Session["xid"] = id;
Session["xyd"] = yd;

string xid = (string)Session["xid"];
string xyd = (string)Session["xyd"];
db = new DBAccess();
sql1 = "select ydjh from ydpy where Tcbh='" + id + "' and pyyd='" + yd + "'";
DataSet dv1 = db.executeQuery(sql1);
if (dv1.Tables[0].Rows.Count > 0)
{
str1 = dv1.Tables[0].Rows[0]["ydjh"].ToString();
TextBox1.Text = str1;
}

}
}

#3
梦灵儿2007-09-12 13:24
  把请求过来的值打印出来看哈.然后在把修改的值查出来看看值有没取出来
#4
ice_beiyu2007-09-12 13:31
谢谢,结贴。
就是少了这个
1