前台代码: <table cellspacing="1" cellpadding="5" width="99%" align="center" bgcolor="#DCEFFA" border="0"> <tr bgcolor="F2F9FD"> <td colspan="2"> <strong><font color="#007EA8">房型分类管理</font></strong></td> </tr> <tr bgcolor="#ffffff"> <td style="width: 20%"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DataList ID="dlHouseType" runat="server" RepeatColumns="1" DataKeyField="ID" OnItemCommand="dlHouseType_ItemCommand"> <ItemTemplate> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td> <asp:TextBox ID="txtTypeName" runat="server" Text='<%# Eval("TypeName") %>'></asp:TextBox> </td> <td> <asp:TextBox ID ="txtOrderIndex" runat="server" Width="35px" Text ='<%# Eval("OrderIndex") %>'></asp:TextBox> <asp:Button ID="btnUpdate" runat="server" Text="修 改" CommandName = "update" /> <asp:Button ID="btnDelete" runat="server" Text="删 除" commandName ="delete" OnClientClick='<%#Eval("TypeName","return confirm(/"您确认要删除:{0}吗?/")")%>' /> </td> </tr> </table> </ItemTemplate> </asp:DataList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" /> </Triggers> </asp:UpdatePanel> </td> </tr> <tr align="center" bgcolor="#ffffff"> <td colspan="2"> <div align="left"> <%--<asp:Button ID="btnOK" Text="提交" runat="server" />--%> </div> </td> </tr> </table> 后台代码: public partial class FangXingType : System.Web.UI.Page { #region ***房型分类*** #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindDataList();//绑定DataList } } private string sql = ""; private Sy_ZX_FangXing fangXing = null; #region 方法 /// <summary> /// 绑定房型分类信息 /// </summary> private void BindDataList() { sql = "SELECT * from ZX_HouseType ORDER BY OrderIndex ASC"; DataTable dt = SelectEntity.BaseAccess.GetDataTable(sql); dlHouseType.DataSource = dt; dlHouseType.DataBind(); } #endregion #region 事件 /// <summary> /// 添加房型类型 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { string typeName = txtHouseType.Text; fangXing = Websharp.ORM.Base.EntityManager.CreateObject(typeof(Sy_ZX_FangXing)) as Sy_ZX_FangXing; fangXing.TypeName = typeName; fangXing.OrderIndex = 1; SelectEntity.BaseAccess.AddNew(fangXing); BindDataList(); } /// <summary> /// 修改删除事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void dlHouseType_ItemCommand(object source, DataListCommandEventArgs e) { int index = e.Item.ItemIndex; //获取数据 int ID = int.Parse(dlHouseType.DataKeys[index].ToString()); TextBox tbox = (TextBox)dlHouseType.Items[index].FindControl("txtTypeName"); string typeName = tbox.Text.Trim(); tbox = (TextBox)dlHouseType.Items[index].FindControl("txtOrderIndex"); int orderIndex = int.Parse(tbox.Text.Trim()); if (e.CommandName == "update") { sql = "update Zx_houseType set TypeName = '" + typeName + "',OrderIndex = " + orderIndex + " where ID=" + ID + ""; SelectEntity.BaseAccess.Update(sql); ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('修改成功!');", true); } if (e.CommandName == "delete") { //SelectEntity.BaseAccess.Delete( //Response.Write("<mce:script type="text/javascript"><!-- alert('删除成功!'); // --></mce:script>"); } BindDataList(); } #endregion } 由于前台试用AJAX的原因,所以后台采用注册脚本方法输出提示(Response.Write("<script>alert('删除成功!');</scirpt>");与AJAX冲突 )