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();
}

浙公网安备 33010602011771号