1.首先展示列表 ashx 讲究的是个替换 这些就是属于ashx麻烦的地方

   public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
List<UserInfo>list= UserInfoService.GetEntityList();
// List<UserInfo>list=UserInfoService.GetEntityList();
StringBuilder sb = new StringBuilder();
foreach (UserInfo userInfo in list)
{
sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td
><a href='ShowDetail.ashx?id={5}'>详细</a></td><td>删除</td><td><a href='Edit.ashx?id={5}'>修改</a></td></tr>",
userInfo.ID, userInfo.UserName, userInfo.UserPass, userInfo.RegTime.ToShortDateString(), userInfo.Email, userInfo.ID);
}
string filePath = context.Request.MapPath("UserInfoList.html");
string fileContent = File.ReadAllText(filePath);
fileContent= fileContent.Replace("$tbody",sb.ToString());
context.Response.Write(fileContent);
}

修改

  public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
int id;
if (int.TryParse(context.Request.QueryString["id"], out id))
{
//1从Bll 里面获取数据
BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); UserInfo userInfo =UserInfoService.GetModel(id);
//2创建文件名和文件路径
string filePath = context.Request.MapPath("Edit.html");
string fileContent = File.ReadAllText(filePath);
//3 再替换
fileContent= fileContent.Replace("$txtName",userInfo.UserName).Replace("$txtPwd",userInfo.UserPass).Replace("$txtEmail",userInfo.Email).Replace("$txtRegTime",userInfo.RegTime.ToString()).Replace("$txtId",userInfo.ID.ToString());
context.Response.Write(fileContent);
}
}

Edit.html类
1  <form method="post" action="ProcessEdit.ashx">
<input type="hidden" name="txtId" value="$txtId" />
<table>
<tr><td>用户名</td><td><input type="text" name="txtName" value="$txtName" /></td></tr>
<tr><td>密码</td><td><input type="text" name="txtPwd" value="$txtPwd" /></td></tr>
<!-- <tr><td>邮箱</td><td><input type="text" name="txtEmail" value="$txtEmail"/></td></tr>
<tr><td>日期时间</td><td><input type="text" name="txtRegTime" value="$txtRegTime"/></td></tr>-->
<tr><td colspan=""><input type="submit" value="修改用户" /></td></tr>
</table>
</form>
ProcessEdit.ashx类

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
// UserInfo userInfo = new UserInfo();
//userInfo.UserName=context.Request.Form["txtName"];
//userInfo.UserPass=context.Request.Form["txtPwd"];
//userInfo.RegTime = Convert.ToDateTime(context.Request.Form["txtRegTime"]);
//userInfo.Email=context.Request.Form["txtEmail"];
int id=Convert.ToInt32(context.Request.Form["txtId"]);
BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
UserInfo userInfo=UserInfoService.GetModel(id);//查询一下,然后再修改,
userInfo.UserName = context.Request.Form["txtName"];
userInfo.UserPass = context.Request.Form["txtPwd"];
if (UserInfoService.UpdateEntity(userInfo))
{
context.Response.Redirect("UserInfoList.ashx");
}
else
{
context.Response.Write("修改失败");
} }

展示

   public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
int id;
if (int.TryParse(context.Request.QueryString["id"], out id))
{
BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
UserInfo userInfo=UserInfoService.GetModel(id);
string filePath = context.Request.MapPath("ShowDetail.html");
string fileContent = File.ReadAllText(filePath);
fileContent = fileContent.Replace("$name", userInfo.UserName).Replace("$pwd",userInfo.UserPass);
context.Response.Write(fileContent);
}
}
<table>
<tr><td>用户名</td><td>$name</td></tr>
<tr><td>密码</td><td>$pwd</td></tr>
</table>

Ashx增删改查_动软的更多相关文章

  1. SSM整合_年轻人的第一个增删改查_基础环境搭建

    写在前面 SSM整合_年轻人的第一个增删改查_基础环境搭建 SSM整合_年轻人的第一个增删改查_查找 SSM整合_年轻人的第一个增删改查_新增 SSM整合_年轻人的第一个增删改查_修改 SSM整合_年 ...

  2. SSM整合_年轻人的第一个增删改查_查找

    写在前面 SSM整合_年轻人的第一个增删改查_基础环境搭建 SSM整合_年轻人的第一个增删改查_查找 SSM整合_年轻人的第一个增删改查_新增 SSM整合_年轻人的第一个增删改查_修改 SSM整合_年 ...

  3. SSM整合_年轻人的第一个增删改查_新增

    写在前面 SSM整合_年轻人的第一个增删改查_基础环境搭建 SSM整合_年轻人的第一个增删改查_查找 SSM整合_年轻人的第一个增删改查_新增 SSM整合_年轻人的第一个增删改查_修改 SSM整合_年 ...

  4. Oracle学习总结_day01_day02_表的创建_增删改查_约束

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 更新: SELECT * FROM (SELECT R ...

  5. 论坛模块_版块管理_增删改查&实现上下移动

    论坛模块_版块管理1_增删改查 设计实体Forum.java public class Forum { private Long id; private String name; private St ...

  6. 1.SSM整合_单表的增删改查

    目标:增删改查 环境:Maven+Eclipse+Tomcat7+JDK7 思维导图: 表结构 目录结构 依赖 <dependencies> <dependency> < ...

  7. Django基础学习四_数据库的增删改查

    今天主要学习两个东西 1.如何对数据库做增删改查 2.如果将数据库中的数据用html的方式返回到前台 一.对数据库中增删改查操作 1.首先需要先见表,见表的方法我们在“http://www.cnblo ...

  8. 玩下软工项目,第一轮--全局Context的获取,SQLite的建立与增删改查,读取用户通话记录信息

    项目的Github地址:https://github.com/ggrcwxh/LastTime 采用基于git的多人协作开发模式 软件采用mvc设计模式,前端这么艺术的事我不太懂,交给斌豪同学去头疼了 ...

  9. Hibernate入门_增删改查

    一.Hibernate入门案例剖析:  ①创建实体类Student 并重写toString方法 public class Student { private Integer sid; private ...

随机推荐

  1. Project Server2016升级安装问题项目中心无法显示

    sharepoint 2016升级后,project server 相关中心页面出现空白页面,这是是sharepoint2016一个bug,解决方案用PWA.resx内容替换PWA.en-us.res ...

  2. XML解析,出现ClassCastException 原因

    import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.Docum ...

  3. windows7 8 mac 安装docker

    安装: 下载 DockerToolbox.exe 苹果的也可以用这个链接下载 一直点击下一步(网络要求很高安装时,网络不好会报错 多点几次就好了)

  4. python的pip 安装

    python的pip 安装 python有很多好用的包,但是需要的时候一一安装实在是麻烦,还好有pip这么好用的安装工具.所以第一步是安装pip,然后其它软件都so easy! 文章来源:https: ...

  5. 【linux安装软件步骤】

    一.解析linux应用软件安装包: 通常Linux应用软件的安装包有三种: tar包,如software-1.2.3-1.tar.gz.它是使用UNIX系统的打包工具tar打包的. rpm包,如sof ...

  6. Note: Improving Restore Speed for Backup Systems that Use Inline Chunk-Based Deduplication

    思路/方法 Measuring restore speed 提出了speed-factor,用以衡量存储速度. Container capping 限制恢复文件时使用的container个数,为了保证 ...

  7. Boost Python学习笔记(三)

    你将学到什么 在C++中调用Python代码时的传参问题 基础类型 继续使用前面的项目,但是先修改下Python脚本(zoo.py),添加Add和Str函数,分别针对整数.浮点数和字符串参数的测试 d ...

  8. 读《JavaScript权威指南》笔记(一)

    1.Number()  parseInt()  parseFloat() 如果通过Number()转换函数传入一个字符串,它会试图将其转换为一个整数或浮点数直接量,这个方法只能基于十进制数进行转换,并 ...

  9. java工具类学习整理——集合

    好久没有总结一些东西了,同时集合部分的知识点也学习的比较早了,但是从来没有抽时间去研究和学习,今天正好有时间就总结一下map常用的遍历方法: package runningwhile; import ...

  10. go语言web开发框架_Iris框架讲解(五)MVC包使用

    在Iris框架中,封装了mvc包作为对mvc架构的支持,方便开发者遵循mvc的开发原则进行开发. iris框架支持请求数据.模型.持久数据分层处理,并支持各层级模块代码绑定执行. MVC即:model ...