GridView ---普通事件中获取GrieView行数据

protected void update_Click(object sender, EventArgs e)
    {

      for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            StringBuilder query = new StringBuilder();
            GridViewRow row = GridView1.Rows[i];
            string empID = ((TextBox)row.Cells[0].FindControl("txtID")).Text.Replace("'", "");
            string empRealName = ((TextBox)row.Cells[0].FindControl("txtRealName")).Text.Replace("'", "");
            string empSex = ((DropDownList)row.Cells[0].FindControl("ddlSex")).SelectedValue;
            string empAddress = ((TextBox)row.Cells[0].FindControl("txtAddress")).Text.Replace("'", "");
            query.Append("update Employee set EmpID='" + empID + "',EmpRealName='" + empRealName + "',EmpSex='" + empSex + "',EmpAddress='" + empAddress + "' where ID=" + GridView1.DataKeys[i].Value + "");
            Common.ExecuteSql(query.ToString());
        }
        bind();
    }

posted @ 2010-09-29 10:13  赵良  阅读(180)  评论(0)    收藏  举报