asp:HyperLinkField 问题
我在GridView里添加了一个<asp:HyperLinkField DataNavigateUrlFields="xwid" DataNavigateUrlFormatString="add_thxw.aspx?xwid={0}" HeaderText="修改" Text="修改" >
<ItemStyle Width="40px" />
</asp:HyperLinkField>
点这一连接时进入add_thxw.aspx?xwid={0}
根据xwid这个参数进行修改.并在add_thxw.aspx[这个页面加载
protected void Page_Load(object sender, EventArgs e)
{
str = (string)Request.QueryString["xwid"];
if (!(str == null)&&!(str.Equals("")))
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/tianhao.mdb");
string mysql = "SELECT * from thxw where xwid=@xwid";
OleDbConnection cn = new OleDbConnection(strconn);
OleDbCommand cm = new OleDbCommand(mysql,cn);
cm.Parameters.Add("@xwid",OleDbType.Integer);
cm.Parameters["@xwid"].Value = int.Parse(str);
cn.Open();
OleDbDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
//tb_xwbt.Text = dr["xwbt"].ToString();
//tb_xwnr.Text = dr["xwnr"].ToString();
//if (int.Parse(dr["xwbk"].ToString()) == 1) ddl_xwfl.SelectedValue = "1";
//if (int.Parse(dr["xwbk"].ToString()) == 2) ddl_xwfl.SelectedValue="2";
}
cn.Close();
ddl_xwfl.Enabled = false;
}
}
使相应的方本框中显示数据库中的相应值.进行了
//tb_xwbt.Text = dr["xwbt"].ToString();
//tb_xwnr.Text = dr["xwnr"].ToString();
//if (int.Parse(dr["xwbk"].ToString()) == 1) ddl_xwfl.SelectedValue = "1";
//if (int.Parse(dr["xwbk"].ToString()) == 2) ddl_xwfl.SelectedValue="2";
绑定.
可是执行add_thxw.aspx页面一个提交按纽更新数据库中的内容,
可是数据库的这二个字段值没有改变.
[bo]提交事件的click事个如下:[/bo]
protected void Button1_Click(object sender, EventArgs e)
{
//string str = (string)Request.QueryString["xwid"];
string bt = tb_xwbt.Text;
string nr = tb_xwnr.Text;
int bk=0;
if (ddl_xwfl.SelectedValue == "1") bk = 1;
if (ddl_xwfl.SelectedValue == "2") bk = 2;
DateTime time = DateTime.Now;
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/tianhao.mdb");
string in_sql = "insert into thxw(xwbt,xwbk,scsj,xwnr)values('"+bt+"',@bk,'"+time+"','"+nr+"')";
string up_sql = "update thxw set xwbt='"+bt+"' ,scsj='" + time + "',xwnr='"+nr+"'where xwid=@str";
OleDbConnection in_conn,up_conn;
in_conn = new OleDbConnection(strconn);
up_conn = new OleDbConnection(strconn);
if (!(str == null) && !(str.Equals("")))
{
up_conn.Open();
OleDbCommand cm = new OleDbCommand(up_sql, up_conn);
//cm.Parameters.Add("@bt", OleDbType.VarChar,255);
//cm.Parameters.Add("@nr", OleDbType.VarChar);
cm.Parameters.Add("@str", OleDbType.Integer);
// cm.Parameters["@bt"].Value =bt;
//cm.Parameters["@nr"].Value =nr;
cm.Parameters["@str"].Value = int.Parse(str);
cm.ExecuteNonQuery();
up_conn.Close();
Response.Redirect("admin_thxw.aspx");
}
else
{
// MyConn = new OleDbConnection(strconn);
in_conn.Open();
OleDbCommand cm = new OleDbCommand(in_sql, in_conn);
cm.Parameters.Add("@bk", OleDbType.Integer);
cm.Parameters["@bk"].Value =bk;
cm.ExecuteNonQuery();
in_conn.Close();
tb_xwbt.Text = "";
tb_xwnr.Text = "";
string js = @"alert('添加新闻成功!');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "js", js, true);
}
}