//保存重命名 protected void Save_Click(object sender, EventArgs e) { Button but = (Button)sender; GridViewRow row = (GridViewRow)but.NamingContainer; //获取当前行id int id = int.Parse(row.Cells[0].Text); TextBox textBox = (TextBox)row.FindControl("ReName_text"); //获取要修改的新名字 string newName = textBox.Text.Trim(); //判断操作对象并执行操作 string table_name = Request.QueryString["name"]; bool r = false; if (newName != "") { switch (table_name) { case "type": TypeList type = new TypeList(); r = type.UpdateOne(id, newName); break; case "place": PlaceList place = new PlaceList(); r = place.UpdateOne(id, newName); break; } } BuildView(); if (r) { ClientScript.RegisterStartupScript(GetType(), "", "window.alert('修改成功');", true); } else { ClientScript.RegisterStartupScript(GetType(), "", "window.alert('修改失败');", true); } }