各位大侠有好的,用过的例子吗?贴段代码上来看看啊。

解决方案 »

  1.   

    private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    //取得编辑行的关键字段的值
    string userid=(string)DataGrid1.DataKeys[e.Item.ItemIndex];
    //取得文本框中输入的内容
    TextBox newposition = (TextBox)e.Item.FindControl("Txtposition");
    string sqlstr="update gz_users_info set position='"+newposition.Text+"'where userid='"+userid.ToString()+"'";
               
    OracleConnection oOracleConn = new OracleConnection();
    oOracleConn.ConnectionString ="Data Source=AGENTDB;User Id=agentdba;Password=icbcsg;Integrated Security=no;";
    OracleCommand cmd=new OracleCommand(sqlstr,oOracleConn);
    oOracleConn.Open(); 
    try
    {   //执行
    cmd.ExecuteNonQuery();
    //取消编辑
    DataGrid1.EditItemIndex = -1;
    DataGridDataBind();
    }
    catch(Exception err)
    {
    //输出异常信息
    Response.Write(err.ToString());
    }
    finally
    {
    //关闭连接对象
    oOracleConn.Close();
    }
    我测试通过的!
      

  2.   

    private void DtgUser_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    string UserID=DtgUser.DataKeys[e.Item.ItemIndex].ToString();
    TextBox _txtBox;
    CheckBox _chk;
    CheckBox _chk1;
    _txtBox=(TextBox)e.Item.FindControl("TxtPath");
    _chk=(CheckBox)e.Item.FindControl("ChkPassEdit");
    _chk1=(CheckBox)e.Item.FindControl("ChkManagerEdit");
    string Power;
    if(_chk1.Checked)
    Power="1";
    else
    Power="0";
    string vPath=_txtBox.Text;
    string pass=_chk.Checked.ToString();
    DbControl _dbcontrol=new DbControl();
    int i=_dbcontrol.USER_UPDATE(vPath,pass,UserID,Power);
    if(i==1)
    Response.Write("<script>window.alert('修改成功!')</script>");
    DtgUser.EditItemIndex=-1;
    DtgUserBinding();
    }