关于IsPostBack操作数据库的问题
有个简单的页面,刚打开时从数据中获取一个记录。
然后给用户修改
修改完后按保存。
这在WINFORM里是没问题的,可是WEBFORM就总是刚打开的值。貌似IsPostBack的问题,可无论我怎加IsPostBack,都没效
源码如下
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = datas.Query("select * from intro where id=1");
intro.Text = ds.Tables[0].Rows[0]["intro"].ToString();
maxim.Text = ds.Tables[0].Rows[0]["maxim"].ToString();
address.Text = ds.Tables[0].Rows[0]["address"].ToString();
bot_zongzhi.Text = ds.Tables[0].Rows[0]["bot_zongzhi"].ToString();
bot_linian.Text = ds.Tables[0].Rows[0]["bot_linian"].ToString();
bot_yuanfeng.Text = ds.Tables[0].Rows[0]["bot_yuanfeng"].ToString();
bot_shide.Text = ds.Tables[0].Rows[0]["bot_shide"].ToString();
bot_mubiao.Text = ds.Tables[0].Rows[0]["bot_mubiao"].ToString();
msg.Text = IsPostBack.ToString();
}
}
protected void saved_Click(object sender, EventArgs e)
{
string sql = @"update intro set
intro='" + intro.Text + "'," +
"maxim='" + maxim.Text + "'," +
"address='" + address.Text + "'," +
"bot_zongzhi='" + bot_zongzhi.Text + "'," +
"bot_linian='" + bot_linian.Text + "'," +
"bot_yuanfeng='" + bot_yuanfeng.Text + "'," +
"bot_shide='" + bot_shide.Text + "'," +
"bot_mubiao='" + bot_mubiao.Text + "' where id=1";
if (datas.ExecuteSQL(sql) > 0)
{
msg.Text = "成功保存" + sql;
}
else
{
msg.Text = "保存失败";
}
}
在界面设计li 我只加了TEXTBOX,和一个保存按钮。其他没加。