UpdatePanel 与 Gridview 要实现无刷新增加,修改,删除,分页。 增加,删除,分页 都能运行成功,修改功能未能实现,点击 “编辑” 就会出现“更新”和“取消”。取消没有问题,但是更新这个做不了。每一次输入新的内容,再点击“更新”,它又会变会原来的。
上网查过很多资料。估计是,updatePanel 对 更新按钮调用不了updating 方法。
aspx代码
- C# code
<%@ Page Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="true" CodeFile="RoleInfo.aspx.cs" Inherits="Admin_RoleInsert" Title="设备管理后台系统" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <link rel="Stylesheet" type="text/css" href="../Admin/css/Modular.css" /></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div class="webmap"> </div> <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"> </asp:ScriptManagerProxy> <div id="ModularName"> 用户角色管理模块</div> <hr class="hr2" /> <div id="ModularContent"> <div class="title"> <h1> 增加用户角色</h1> <table> <tr> <td> <asp:Label ID="labName" runat="server" Text="新角色名称:"></asp:Label> </td> <td> <asp:TextBox ID="tbxrolename" runat="server" ValidationGroup="addRo"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="addRo" ControlToValidate="tbxrolename" runat="server" ErrorMessage="请输入类别名字!" Text="*"></asp:RequiredFieldValidator> </td> <td> <asp:Button ID="addbtn" runat="server" Text="增加角色" ValidationGroup="addRo" OnClick="addbtn_Click" /> <asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="addRo" ShowMessageBox="true" ShowSummary="false" runat="server" /> </td> </tr> </table> </div> <hr class="hr2" /> [color=#FF0000] <asp:UpdatePanel ID="MyUpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"[/color]> <ContentTemplate> <div class="list"> <asp:GridView ID="gvRoleInfo" runat="server" AutoGenerateColumns="False" AllowPaging="True" GridLines="Horizontal" BorderColor="#CAD9EA" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="gvRoleInfo_PageIndexChanging" OnRowUpdating="gvRoleInfo_RowUpdating" OnRowEditing="gvRoleInfo_RowEditing" OnRowCancelingEdit="gvRoleInfo_RowCancelingEdit" OnRowDeleting="gvRoleInfo_RowDeleting"> <RowStyle CssClass="RowStyle1" /> <FooterStyle BackColor="White" ForeColor="#333333" /> <PagerStyle CssClass="PagerStyle1" /> <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" /> <HeaderStyle CssClass="HeadStyle1" /> <AlternatingRowStyle CssClass="AltRowStyle1" /> <EditRowStyle CssClass="EditRowStyle1" /> <Columns> <asp:BoundField DataField="roleId" HeaderText="角色编号" ReadOnly="true" /> <asp:BoundField DataField="roleName" HeaderText="角色名称" /> <asp:CommandField HeaderText="编辑" ShowEditButton="True" /> <asp:CommandField HeaderText="删除" ShowDeleteButton="True" /> <asp:TemplateField> <ItemTemplate> <asp:Button ID="button" runat="server" Text="更新" UseSubmitBehavior="false" /> </ItemTemplate> </asp:TemplateField> </Columns> <PagerTemplate> ...... </PagerTemplate> </asp:GridView> <br /> </div> </div> </ContentTemplate> <Triggers> </Triggers> </asp:UpdatePanel></asp:Content>