该网页是由一个母版页Web.config和两个子页AddInfo.aspx, InformationList.aspx组成

该网页内的所有数据,存储于DataSet下一个名为DtEntity的DataTable

首先在Web.config配置一个key,存储路径:

System.Configuration 命名空间提供了很容易的方法来访问配置值,最简单的方法是用ConfigurationManager 访问配置数据。下面的例子演示如何从配置文件中装载简单的键-值对;假设已有下面的配置文件,准备读“MySetting”值:

<configuration>

  <appSettings>

    <add key="MySetting"value="An important string" />

  </appSettings>

</configuration>

  <appSettings>
    <add key="DataPath" value="~/Resources/Entity.xml"/>
  </appSettings>

New一个获取数据的类:

 1     public class ConfigReader
 2     {
 3         public static string DataPath
 4         {
 5             get
 6             {
 7                 return System.Configuration.ConfigurationManager.AppSettings["DataPath"];
 8             }
 9         }
10     }

再New一个读写数据库的类:

 1     public class EntityRepository
 2     {
 3         public DsDesc.DtEntityDataTable GetEntities()
 4         {
 5             DsDesc ds = new DsDesc();
 6             if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(ConfigReader.DataPath)))    //Read
 7             {
 8                 ds.ReadXml(HttpContext.Current.Server.MapPath( ConfigReader.DataPath));
 9             }
10             return ds.DtEntity;
11         }
12
13         public void SaveEntities(DsDesc.DtEntityDataTable table )
14         {
15             table.DataSet.WriteXml(HttpContext.Current.Server.MapPath(ConfigReader.DataPath),XmlWriteMode.WriteSchema);  //Write
16         }
17     }

International List

<%@ Page Title="InformationList" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="InformationList.aspx.cs" Inherits="Sabrina.Web.InformationList" %><asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"><hgroup class="title"><h1><%: Title %>.</h1><h2>2018 Sailor Moon&nbsp;</h2></hgroup><article><p>        <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged=" GridView1_SelectedIndexChanged" Height="231px" Width="424px" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting"><Columns> <asp:BoundField HeaderText="EntityID" DataField="EntityID" Visible="False" /><asp:BoundField DataField="EntityName" HeaderText="Name" /><asp:BoundField DataField="EntityPhone" HeaderText="Phone" /><asp:BoundField DataField="EntityEmail" HeaderText="Email" /><asp:BoundField DataField="EntityAddress" HeaderText="Address" /><asp:TemplateField HeaderText="Edit"><ItemTemplate ><asp:HyperLink ID ="EntityID" runat ="server" Text ="Edit"  NavigateUrl ='<%#Eval("EntityID","AddInfo.aspx?id={0}")%>'></asp:HyperLink></ItemTemplate></asp:TemplateField><asp:ButtonField CommandName="delete" HeaderText="Delete" Text="Delete" />
       </Columns></asp:GridView><asp:Button ID="ButtonAdd" runat="server" Text="Add" Height="47px" Width="216px" OnClick=" buttonAdd_New_Click" /></p><br /><br /><br /></article><aside><h3>Aside Titlele</h3><p>        Use this area to provide additional information.</p><ul><li><a runat="server" href="~/">Home</a></li><li><a runat="server" href="~/InformationList">InformationList</a></li><li><a runat="server" href="~/Contact">Contact</a></li></ul></aside>
</asp:Content>

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 using System.Data;
 8 using System.Data.SqlClient;
 9
10 namespace Sabrina.Web
11 {
12     public  partial class InformationList : Page
13     {
14         protected void Page_Load(object sender, EventArgs e)
15         {
16             //TO DO:
17             if(!IsPostBack)
18             {
19                 EntityRepository repository = new EntityRepository();
20                 GridView1.DataSource = repository.GetEntities();
21                 GridView1.DataBind();
22             }
23         }
24
25         protected void buttonAdd_New_Click(object sender, EventArgs e)
26         {
27             this.Response.Redirect("~/AddInfo.aspx");
28         }
29
30         protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
31         {
32             EntityRepository repository = new EntityRepository();
33             DsDesc.DtEntityDataTable dt = repository.GetEntities();
34             int index = e.RowIndex;  //获取产生事件的行
35             dt.Rows[index].Delete();
36
37             repository.SaveEntities(dt);
38             this.Response.Redirect("~/InformationList.aspx");
39             //GridView1.DataBind();
40
41         }
42         protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
43         {
44
45         }
46     }
47 }

AddInfo

%@ Page Title="AddInformation" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AddInfo.aspx.cs" Inherits="Sabrina.Web.AddInfo" %><asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"><hgroup class="title"><h1><%: Title %>.</h1><h2>Sailor Moon New member </h2></hgroup><section class="AddInfo"><header><h3>Personal Info:</h3></header><p style="margin-left: 40px"><span class="label">Entity Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><asp:TextBox ID="TextBoxEntityName" runat="server" Height="16px" Width="287px" OnTextChanged="TextBoxName"></asp:TextBox></p><p style="margin-left: 40px"><span class="label">Entity Phone:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="TextBoxEntityPhone" runat="server" Height="16px" Width="287px" OnTextChanged="TextBoxPhone"></asp:TextBox></p><p style="margin-left: 40px"><span class="label">Entity Email:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="TextBoxEntityEmail" runat="server" Height="16px" Width="287px" OnTextChanged="TextBoxEmail"></asp:TextBox></p><p style="margin-left: 40px"><span class="label">Entity Address:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><asp:TextBox ID="TextBoxEntityAddress" runat="server" Height="16px" Width="287px" OnTextChanged="TextBoxAddress"></asp:TextBox></p></section><section class="AddInfo"><div><h3>Career Objective</h3></div><p style="margin-left: 40px"><span class="label">You want to be a:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:DropDownList ID="DropDownList1" runat="server" Height="36px" OnSelectedIndexChanged="DropDownList1_Career" Width="302px"></asp:DropDownList></p><p style="margin-left: 40px"><span class="label">Are you willing to accept to adjust:</span></p><p style="margin-left: 200px"><asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButtonAdjustY" /><asp:RadioButton ID="RadioButton2" runat="server" OnCheckedChanged="RadioButtonAdjustN" /></p><p style="margin-left: 40px"><span class="label">Other items you might interest :</span></p><p style="margin-left: 200px"><asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBoxCheckedChanged" /><asp:CheckBox ID="CheckBox3" runat="server" OnCheckedChanged="CheckBoxCheckedChanged" /><asp:CheckBox ID="CheckBox4" runat="server" OnCheckedChanged="CheckBoxCheckedChanged" /><asp:CheckBox ID="CheckBox5" runat="server" OnCheckedChanged="CheckBoxCheckedChanged" /></p></section><section class="AddInfo"><div><h3>Apply Reason:</h3><p style="margin-left: 40px"><span class="label">Description:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p style="margin-left: 160px"><asp:TextBox ID="TextBoxEntityDescription" runat="server" Height="122px" Width="399px" OnTextChanged="TextBoxEntityDescription_TextChanged"></asp:TextBox></p><h3>Attachment:</h3></div><p style="margin-left: 40px"><span class="label">Reference:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p><p style="margin-left: 160px"><asp:FileUpload ID="FileUpload1" runat="server" Height="28px" Width="450px" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="Button1" runat="server" OnClick="ButtonUpload" Text="Upload" Height="43px" Width="121px" /></p><p style="margin-left: 160px"><asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_Click" /></p></section>
</asp:Content>
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Web;
  5 using System.Web.UI;
  6 using System.Web.UI.WebControls;
  7 using System.Data;
  8 using System.Data.SqlClient;
  9
 10 namespace Sabrina.Web
 11 {
 12     public partial class AddInfo : Page
 13     {
 14         protected void Page_Load(object sender, EventArgs e)
 15         {
 16             if (!IsPostBack)
 17             {
 18                 string id = Request["id"];
 19                 if (!string.IsNullOrEmpty(id))                                      // 判断是编辑页还是新建页
 20                 {
 21                     //Edit
 22                     EntityRepository repository = new EntityRepository();
 23                     DsDesc.DtEntityDataTable dt = repository.GetEntities();
 24                     foreach (var item in dt.Rows)
 25                     {
 26                         DsDesc.DtEntityRow row = item as DsDesc.DtEntityRow;
 27                         if (id == row.EntityID)
 28                         {
 29                             TextBoxShow(row);
 30                             break;
 31                         }
 32                     }
 33                 }
 34                 else {
 35                     //Add
 36                 }
 37             }
 38         }
 39
 40         protected void ButtonSave_Click(object sender, EventArgs e)
 41         {
 42
 43             #region 原版
 44             // DataSet ds = new DataSet("MyTable");
 45             //if (dt == null)
 46             //{
 47                 //dt.Columns.Add("EntityID");//添加列
 48                 //dt.Columns.Add("EntityName");
 49                 //dt.Columns.Add("EntityPhone");
 50                 //dt.Columns.Add("EntityEmail");
 51                 //dt.Columns.Add("EntityAddress", typeof(String));
 52                 //dt.Columns.Add("EntityCareer", typeof(Int32));
 53                 //dt.Columns.Add("IfAdjust", typeof(bool));
 54                 //dt.Columns.Add("Interests", typeof(String));
 55                 //dt.Columns.Add("Reason", typeof(String));
 56                 //dt.Columns.Add("Reference", typeof(String));
 57             #region
 58                 //  ds.Tables.Add(dt);
 59
 60                 //for (int i = 0; i < dt.Rows.Count; i++)
 61                 //{
 62                 //    if (dt.Rows[i] == null)//DataControlRowType.DataRow
 63                 //    {
 64
 65                 //    }
 66                 //    else {
 67
 68                 //    }
 69
 70                 //}
 71                 #endregion
 72
 73             //}
 74             #endregion
 75             string id = Request["id"];
 76             EntityRepository repository = new EntityRepository();
 77             DsDesc.DtEntityDataTable dt = repository.GetEntities();
 78
 79             if (!string.IsNullOrEmpty(id))                                        //判断Save的是编辑还是新建内容
 80             {
 81                 //Edit
 82                 foreach (var item in dt.Rows)
 83                 {
 84                     DsDesc.DtEntityRow row = item as DsDesc.DtEntityRow;
 85                     if (id == row.EntityID)
 86                     {
 87                         TextBoxEntity(row);
 88                         break;
 89                     }
 90                 }
 91             }
 92             else
 93             {
 94                 //Add
 95                 DsDesc.DtEntityRow row = dt.NewDtEntityRow();
 96
 97                 row.EntityID = Guid.NewGuid().ToString();
 98                 TextBoxEntity(row);
 99
100                 dt.Rows.Add(row);
101             }
102
103             repository.SaveEntities(dt);
104             this.Response.Redirect("~/InformationList.aspx");
105
106             #region 原版
107             //DataRow dr = dt.NewRow();
108             ////dt.Rows[dt.Rows.Count] =
109             //dr["EntityID"] = Guid.NewGuid().ToString();// dr["EntityID"]
110             //dr["EntityName"] = this.TextBoxEntityName.Text;
111             //dr["EntityPhone"] = this.TextBoxEntityPhone.Text;
112             //dr["EntityEmail"] = this.TextBoxEntityEmail.Text;
113             //dr["EntityAddress"] = this.TextBoxEntityAddress.Text;
114             //// dr["EntityCareer"] = this.TextBoxEntityCareer.Text;
115             //dt.Rows.Add(dr);
116             //}
117
118            // Session["Entities"] = dt;
119             // dt.WriteXml(Server.MapPath("~/Resources/Entities.xml"));//schema
120             #endregion
121
122
123         }
124         protected void TextBoxEntity(DsDesc.DtEntityRow row)                      //将TextBox内容存入DtEntity
125         {
126             row.EntityName = this.TextBoxEntityName.Text;
127             row.EntityPhone = this.TextBoxEntityPhone.Text;
128             row.EntityEmail = this.TextBoxEntityEmail.Text;
129             row.EntityAddress = this.TextBoxEntityAddress.Text;
130         }
131
132         protected void TextBoxShow(DsDesc.DtEntityRow row)                        //DtEntity内容在TextBox中显示出来
133         {
134             this.TextBoxEntityName.Text = row.EntityName;
135             this.TextBoxEntityPhone.Text = row.EntityPhone;
136             this.TextBoxEntityEmail.Text = row.EntityEmail;
137             this.TextBoxEntityAddress.Text = row.EntityAddress;
138         }
139
140         #region OnClick****
141         protected void TextBoxEntityDescription_TextChanged(object sender, EventArgs e)
142         {
143
144         }
145
146         protected void TextBoxName(object sender, EventArgs e)
147         {
148
149         }
150
151         protected void TextBoxPhone(object sender, EventArgs e)
152         {
153
154         }
155
156         protected void TextBoxEmail(object sender, EventArgs e)
157         {
158
159         }
160
161         protected void TextBoxAddress(object sender, EventArgs e)
162         {
163
164         }
165
166         protected void DropDownList1_Career(object sender, EventArgs e)
167         {
168
169         }
170
171         protected void RadioButtonAdjustY(object sender, EventArgs e)
172         {
173
174         }
175
176         protected void RadioButtonAdjustN(object sender, EventArgs e)
177         {
178
179         }
180
181         protected void CheckBoxCheckedChanged(object sender, EventArgs e)
182         {
183
184         }
185
186         protected void ButtonUpload(object sender, EventArgs e)
187         {
188
189         }
190
191         #endregion
192
193
194
195
196
197     }
198 }

  代码改进中......

转载于:https://www.cnblogs.com/sabrinana/p/8082495.html

基于DataTabel的增删改查相关推荐

  1. ORM框架之Mybatis(一)基于mapper配置增删改查

    Mybatis是现在非常流行的SSM框架中的M部分,Mybatis也是一个主流的ORM框架,在项目中用来处理持久层数据. 一.Mybatis框架介绍及使用 1.1 mybatis框架概述: mybat ...

  2. 基于localstorage实现增删改查功能

    本文以英雄联盟英雄列表中英雄的增删改查为例,介绍localstorage的增删改查功能 该图显示了增差功能,由于我将图片和英雄名字设置为相同的,所以这里输入英雄名字(我将其命名为1~100的数字)图片 ...

  3. MyBatis研习录(06)——基于注解的增删改查操作

    C语言自学完备手册(33篇) Android多分辨率适配框架 JavaWeb核心技术系列教程 HTML5前端开发实战系列教程 MySQL数据库实操教程(35篇图文版) 推翻自己和过往--自定义View ...

  4. 基于双向链表的增删改查和排序(C++实现)

    双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱.所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点.一般我们都构造双向循环链表 ...

  5. 基于SpringBoot开发一个Restful服务,实现增删改查功能

    点击上方"方志朋",选择"置顶公众号" 技术文章第一时间送达! 作者:虚无境 cnblogs.com/xuwujing/p/8260935.html 前言 在去 ...

  6. boot spring 接口接收数据_基于 Spring Boot 实现 Restful 风格接口,实现增删改查功能...

    优质文章,及时送达 Spring Boot介绍 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配 ...

  7. ext store 数据修改_Go 数据存储篇(一):基于内存存储实现数据增删改查功能...

    在 Web 编程中,经常需要处理用户请求数据,而用户请求数据的处理往往又涉及到数据存储与获取,支持存储数据的媒介很多,包括内存.文件系统.数据库等,接下来,学院君将花几个篇幅的教程来系统介绍 Go W ...

  8. 基于 Spring Boot 的 Restful 风格实现增删改查

    前言 在去年的时候,在各种渠道中略微的了解了SpringBoot,在开发web项目的时候是如何的方便.快捷.但是当时并没有认真的去学习下,毕竟感觉自己在Struts和SpringMVC都用得不太熟练. ...

  9. 基于 abp vNext 和 .NET Core 开发博客项目 - 自定义仓储之增删改查

    基于 abp vNext 和 .NET Core 开发博客项目 - 自定义仓储之增删改查 转载于:https://github.com/Meowv/Blog 本篇说一下自定义仓储的实现方式,其实在ab ...

最新文章

  1. matlab二值化图像_小白啃骨头之图像识别
  2. 在线项目管理软件leangoo 管理 技术支持
  3. asp.net webform html,ASP.NET WebForm页面内容输出方式
  4. 家用工具套装_家居工具一:成为家居维修达人,你可能就差这个:史丹利45件套家用工具箱套装...
  5. opencv 数学操作
  6. Sharding-Proxy安装_以及_sharding-proxy自动分表配置_Sharding-Sphere,Sharding-JDBC分布式_分库分表工作笔记019
  7. Android中GridView实现互相添加和删除
  8. POJ1088(dp)
  9. 【VRP】基于matlab遗传算法求解单中心的车辆路径规划问题【含Matlab源码 059期】
  10. [英语阅读]憧憬利好新政股市收高
  11. 华为薪资等级结构表_华为内部考核体系
  12. 遥感学习笔记(八)——遥感影像
  13. 企业开源办公虚拟专用网工具
  14. MySQL连接错误实例
  15. Vue ElementUI 修改消息提示框样式---messageBox 的大小
  16. 9.来电显示归属地--自定义Toast
  17. 2ASK非相干解调matlab
  18. Python破解携程点击文字验证
  19. AutoIt3 自动化工具
  20. 江西服装学院计算机考试是几级,江西服装学院2018年艺术类报考须知(江苏省)

热门文章

  1. 【STM32】ESP8266 AT指令
  2. android点九,android关于点九(.9)图片
  3. php表达式生成工具,thinkPHP5.0数据查询表达式生成技巧
  4. oracle的OCI目录下没有samples包的解决方案
  5. 计算机屏幕显示电缆借口,电脑关机后显示器显示请检查电缆接口怎么办成功解决...
  6. 记录x86调试命令总结
  7. 防火墙(7)——禁止具体协议
  8. 8086汇编贪吃蛇(随机食物+速度递增)
  9. C++11库中 steady_clock , system_clock和high_resolution_clock的区别
  10. windows与linux中的路径书写,斜杠、反斜杠用法总结