<form action="PersonSave.ashx" method="post"> <input type="hidden" name="action" value="{action}"/> <input type="hidden" name="id" value="{id}"/> 姓名:<input type="text" name="name" value="{name}" />年龄:<input type="text" name="age" value="{age}" /> 性别:(选上就是男的)<input type="checkbox" name="gender" {gender} /> <input type="submit" value="保存" /> </form>
表单保存时,若action为edit,那么后台则需要一个id来具体update哪条数据
if (action=="edit") { int id = Convert.ToInt32(context.Request["id"]); SqlHelper.ExecuteNonQuery("update T_Persons set [email protected],[email protected],[email protected] where [email protected]", new SqlParameter("@Name", strName), new SqlParameter("@Age", strAge), new SqlParameter("@Gender", (strGender!=null)), new SqlParameter("@Id", id)); context.Response.Redirect("PersonList.ashx"); }