• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ARCGIS830208
博客园    首页    新随笔    联系   管理    订阅  订阅

对GridView进行编辑的操作

首先把GridView的属性AutoGeneratEditButton的属性设置为true,然后给GRIDVIEW添加RowUpdating事件,其所写代码如下:

 string 房屋编号 = this.GridView1.DataKeys[e.RowIndex][0].ToString();
        string 楼宇名称 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
        string 单元 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString();
        string 楼层 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString();
        string 面积 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text.ToString();
        string 房屋状态 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text.ToString();
        string 业主姓名 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text.ToString();
        string 性别 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text.ToString();
        string 单位 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[9].Controls[0]).Text.ToString();
        string 电话 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[10].Controls[0]).Text.ToString();
        string 手机 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[11].Controls[0]).Text.ToString();
        string 身份证号 = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[12].Controls[0]).Text.ToString();
        updateyz(房屋编号, 楼宇名称, 单元, 楼层,面积, 房屋状态, 业主姓名, 性别, 单位, 电话, 手机, 身份证号);
        this.GridView1.EditIndex = -1;
        getdata();

然后就是编写updateyz函数:

public void updateyz(string 房屋编号, string 楼宇名称, string 单元,string 楼层, string 面积, string 房屋状态, string 业主姓名, string 性别, string 单位, string 电话, string 手机, string 身份证号)
    {
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/db1.mdb");
        OleDbCommand cmd = new OleDbCommand("update 业主信息表 set 楼宇名称='" + 楼宇名称 + "',单元='" + 单元 + "',楼层='" + 楼层 + "',面积='" + 面积 + "',房屋状态='" + 房屋状态 + "',业主姓名='" + 业主姓名 + "',性别='" + 性别 + "',单位='" + 单位 + "',电话='" + 电话 + "',手机='" + 手机 + "',身份证号='" + 身份证号 + "' where 房屋编号='" + 房屋编号 + "'", con);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

以上所调用的 函数getdata()与上次写getdata函数一样.

posted @ 2008-11-05 14:54  吹过你的风  阅读(855)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3