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

80酷酷网    80kuku.com

  datagrid|翻页 

现在数据库中建立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 #ffffff" face="Arial">
  </FONT>
  

  <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%"/>
         </EditItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn>
         <HeaderTemplate>
          <b>名称</b>
         </HeaderTemplate>
         <ItemTemplate>
          <asp:Label Width="200" Text='<%# DataBinder.Eval(Container.DataItem, "Name").ToString().Trim() %>' runat="server" ID="Label2" NAME="Label2"/>
         </ItemTemplate>
         <EditItemTemplate>
          <asp:TextBox id="

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: