首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 笔记本电脑 | 北大青鸟 | 技术专题 | 电子书下载 | 教学视频 | 源码下载 | 搜索 | 博客 | 论坛
中国IT实验室Dotnet频道
中国IT教育
Google
首页 ASP.NET  C#  XML/WebService ADO.NET VC.NET VB.NET .NET 资讯动态 专题 RSS订阅 讨论 下载
您现在的位置: 中国IT实验室 >> Dotnet >> ASP.NET >> 正文

ASP.NET中修改删除DataGrid行—数据库访问


  创建一个WEB页面,命名为:Add.aspx。
  
  Add.aspx代码:
  
  <%@ Page language="c#" Codebehind="Add.aspx.cs" AutoEventWireup="false" Inherits="TeachShow.Charpter7.AccessDataBase.Add" %>
  
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
  
  <HTML>
  
      <HEAD>
  
         <title>Add</title>
  
         <LINK href="../../Style.css" type="text/css" rel="stylesheet">
  
         <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  
         <meta content="C#" name="CODE_LANGUAGE">
  
         <meta content="JavaScript" name="vs_defaultClientScript">
  
         <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
  
      </HEAD>
  
      <body MS_POSITIONING="GridLayout">
  
         <form id="Form1" method="post" runat="server">
  
             <div align="center">
  
                <center>
  
                    <table class="smallBlack" height="318" cellSpacing="0" cellPadding="0" width="429" border="0">
  
                       <tr>
  
                           <td class="title" vAlign="top" width="429" colSpan="2" height="31">添加一个新的发行者</td>
  
                       </tr>
  
                       <tr>
  
                           <td vAlign="top" width="79" height="23">发行者ID:</td>
  
                           <td vAlign="top" width="350" height="23"><asp:textbox id="TextBox1" runat="server" Height="18px" CssClass="smallRed"></asp:textbox><FONT face="宋体">(以99打头,共4位数字)</FONT></td>
  
                       </tr>
  
                       <tr>
  
                           <td vAlign="top" width="79" height="23"><FONT face="宋体">姓名:</FONT></td>
  
                           <td vAlign="top" width="350" height="23"><asp:textbox id="TextBox2" runat="server" Height="18px" CssClass="smallRed"></asp:textbox></td>
  
                       </tr>
  
                       <tr>
  
                           <td vAlign="top" width="79" height="23"><FONT face="宋体">城市:</FONT></td>
  
                           <td vAlign="top" width="350" height="23"><asp:textbox id="TextBox3" runat="server" Height="18px" CssClass="smallRed"></asp:textbox></td>
  
                       </tr>
  
                       <tr>
  
                           <td vAlign="top" width="79" height="23"><FONT face="宋体">省份:</FONT></td>
  
                           <td vAlign="top" width="350" height="23"><asp:textbox id="TextBox4" runat="server" Height="18px" CssClass="smallRed"></asp:textbox><FONT face="宋体">(2个字符)</FONT></td>
  
                       </tr>
  
                       <tr>
  
                           <td vAlign="top" width="79" height="24"><FONT face="宋体">国家:</FONT></td>
  
                           <td vAlign="top" width="350" height="24"><asp:textbox id="TextBox5" runat="server" Height="18px" CssClass="smallRed"></asp:textbox></td>
  
                       </tr>
  
                       <tr>
  
                           <td vAlign="top" align="center" width="429" colSpan="2" height="24"><asp:linkbutton id="LinkButton1" runat="server">提交到数据库</asp:linkbutton></td>
  
                       </tr>
  
                       <tr>
  
                           <td width="429" height="147" valign="top" colspan="2">
  
                              <asp:DataGrid id="DataGrid1" runat="server" Height="120px" CssClass="general" Width="428px">
  
                                  <ItemStyle Width="50px"></ItemStyle>
  
                                  <Columns>
  
                                     <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" CancelText="取消" EditText="编辑">
  
                                         <HeaderStyle Width="60px"></HeaderStyle>
  
                                     </asp:EditCommandColumn>
  
                                     <asp:ButtonColumn Text="删除" CommandName="Delete"></asp:ButtonColumn>
  
                                  </Columns>
  
                              </asp:DataGrid></td>
  
                       </tr>
  
                    </table>
  
                </center>
  
             </div>
  
         </form>
  
      </body>
  
  </HTML>
  
      Add.asp.cs代码:
  
  using System;
  
  using System.Collections;
  
  using System.ComponentModel;
  
  using System.Data;
  
  using System.Data.SqlClient;
  
  using System.Drawing;
  
  using System.Web;
  
  using System.Web.SessionState;
  
  using System.Web.UI;
  
  using System.Web.UI.WebControls;
  
  using System.Web.UI.HtmlControls;
  
  namespace TeachShow.Charpter7.AccessDataBase
  
  {
  
    /// <summary>
  
    /// Add 的摘要说明。
  
    /// </summary>
  
    public class Add : System.Web.UI.Page
  
    {
  
      protected System.Web.UI.WebControls.TextBox TextBox1;
  
      protected System.Web.UI.WebControls.TextBox TextBox2;
  
      protected System.Web.UI.WebControls.TextBox TextBox3;
  
      protected System.Web.UI.WebControls.TextBox TextBox4;
  
      protected System.Web.UI.WebControls.LinkButton LinkButton1;
  
      protected System.Web.UI.WebControls.DataGrid DataGrid1;
  
      protected System.Web.UI.WebControls.TextBox TextBox5;
  
      private void Page_Load(object sender, System.EventArgs e)
  
      {
  
        // 在此处放置用户代码以初始化页面
  
        if(!this.IsPostBack)
  
        {
  
          this.BindGrid();
  
        }
  
      }
  
      #region Web 窗体设计器生成的代码
  
      override protected void OnInit(EventArgs e)
  
      {
【责编:admin】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·开源软件测试工具学习专题
 ·JSP Web开发 入门基础到高手进阶教程…
 ·JavaFX—是Java桌面的新希望么?
 ·安全至上 .NET开发安全策略…
 ·测试用例设计之道-测试用例学习专题
 ·面向Java开发人员的Scala指南
 ·Java设计模式之实例详解
 ·Oracle数据库11g 面向DBA和开发人员的重要新特性…
 ·桌面应用软件编程 J2SE技术详解…
 ·我“炫”我精彩-------WPF开发教程
 今日更新
 社区讨论
 博客论点
 频道精选
 Dotnet频道相关导航