在GridView中应该用分页、编辑、删除、更新操作!
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。 |
ASPX <asp:GridView ID="gvwDepartments" runat="server" OnRowCancelingEdit="gvDepartment_RowCancelingEdit" OnRowEditing="gvDepartment_RowEditing" OnRowUpdating="gvDepartment_RowUpdating" OnRowDeleting="gvDepartment_RowDeleting"> <Columns> <asp:TemplateField HeaderText="部门名称"> <EditItemTemplate> <asp:TextBox ID="txtDepName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox> <asp:RequiredFieldValidator ID="rfvDepartment" runat="server" ControlToValidate="txtDepName" ErrorMessage="请填写 部门名称。"></asp:RequiredFieldValidator> <asp:HiddenField ID="hfID" runat="server" Value='<%# Bind("ID") %>' /> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label> <asp:HiddenField ID="hfID" Value='<%# Bind("ID") %>' runat="server" /> </ItemTemplate> <ItemStyle Width="400px" /> </asp:TemplateField> <asp:TemplateField ShowHeader="False"> <EditItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="更新"></asp:LinkButton> <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="取消"></asp:LinkButton> </EditItemTemplate> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="编辑"></asp:LinkButton> <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="删除" OnClientClick="return confirm('确定删除该部门信息吗?');"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>要注意的是这几个事件一定不可少 分页:OnPageIndexChanging 编辑:OnRowEditing 更新:OnRowUpdating 退出编辑:OnRowCancelingEdit 删除:OnRowDeleting 在后台类中对其进行定义,实现事件的操作。 本文出自 “共享经验” 博客,转载请与作者联系! 本文出自 51CTO.COM技术博客 |



剑了
博客统计信息
热门文章
最新评论
友情链接