当前位置: 首页 > 图文教程 > 网络编程 > ASP > datagrid编辑、修改、删除、翻页例子

ASP
连接数据库查询手册
ASP.net组件编程中的两种事件编写方法
简单快捷实现ASP在线发邮件
ASP能读写注册表
用ASP实现在线压缩与解压缩
Asp编写不再让人讨厌的自动弹出窗口
使用组件封装ASP的数据库操作
删除Access数词库中的空记录
制做行背景颜色交替变换的表格
将数据库中的信息存储至XML文件中
如何用foreach遍历页面上所有的TextBox
asp.net如何生成图片验证码(简单)
WEB表格导出为EXCEL文档的方法
ASP上两个防止SQL注入式攻击Function
xmlHTTP技术资料
提高ASP.NET性能的方法
DataGrid 分页问题
如何固定表格的标题行和标题列
在B/S系统中引入定时器的功能
关于用ASP.Net识别远程主机服务器种类

ASP 中的 datagrid编辑、修改、删除、翻页例子


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 36 ::
收藏到网摘: n/a

 现在数据库中建立test表,字段分别为ID、Code、Name;

数据库的链接这里就不具体写了,数据库的链接和操作请求我写在了AreaInfo.cs中,代码中会用到,这里声明一下

<%@ Page language="c#" Codebehind="Update.aspx.cs" AutoEventWireup="false" Inherits="Client.Page.AreaInfo.Update" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>test</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout" bgcolor="ivory">
  <font face="arial" size="3"></font><FONT style="BACKGROUND-COLOR: #ffffff" face="Arial">
  </FONT>
  <br>
  <form runat="server" ID="Form1">
   <TABLE id="Table1" cellSpacing="0" bgcolor="#6699cc" cellPadding="1" width="300" border="1">
    <TR>
     <TD><b>test</b>
     </TD>
    </TR>
     <TD>
      <asp:DataGrid id="DG1" runat="server" BorderColor="green" Width="640" PageSize="5" AllowPaging="true"
       OnPageIndexChanged="Page_Grid" BorderWidth="1" CellPadding="3" AutoGenerateColumns="false"
       ShowHeader="true" Visible="true" OnEditCommand="People_Edit" OnCancelCommand="People_Cancel"
       OnUpdateCommand="People_Update" OnDeleteCommand="People_Delete">
       <HeaderStyle BorderColor="White" BackColor="black" ForeColor="White" Font-Bold="True" Font-Name="Arial"
        Font-Size="9" HorizontalAlign="Center" />
       <ItemStyle BorderColor="" BackColor="#FFFFF0" ForeColor="Black" Font-Name="Arial" Font-Size="8"
        Font-Bold="False" HorizontalAlign="Center" />
       <EditItemStyle BorderColor="" BackColor="#FFFFF0" ForeColor="Black" Font-Name="Arial" Font-Size="7"
        Font-Bold="False" HorizontalAlign="Center" />
       <PagerStyle Mode="NumericPages" Font-Size="8" />
       <Columns>
        <asp:BoundColumn HeaderText="ID" ReadOnly="true" DataField="ID" />
        <asp:TemplateColumn>
         <HeaderTemplate>
          <b>代码</b>
         </HeaderTemplate>
         <ItemTemplate>
          <asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "Code").ToString().Trim() %>' runat="server" ID="Label1" NAME="Label1"/>
         </ItemTemplate>
         <EditItemTemplate>
          <asp:TextBox id="Code" Text='<%# DataBinder.Eval(Container.DataItem, "Code").ToString().Trim() %>' runat="server" Width="100%"/>