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. stm32之外设控制

    本文将提到以下内容: 蜂鸣器 按键控制 电容触摸 温度传感器 红外 TFTLCD触摸屏 MPU6050传感器 SPI-FLASH SDIO_SD卡 ucos-III移植 一.蜂鸣器 蜂鸣器是一种一体化 ...

  2. URL网址规范化

    网址URL规范化(URL canonicalization)是近一年来在Google搜索结果中出现的一个很大的问题.它指的是搜索引擎挑选最好的URL网址作为真正网址的过程.举例来说,下面这几个URL一 ...

  3. HBase 官方文档

    HBase 官方文档 Copyright © 2010 Apache Software Foundation, 盛大游戏-数据仓库团队-颜开(译) Revision History Revision ...

  4. 十道海量数据处理面试题 - 数据分析与数据挖掘技术-炼数成金-Dataguru专业数据分析社区

    1.海量日志数据,提取出某日访问百度次数最多的那个IP. 首先是这一天,并且是访问百度的日志中的IP取出来,逐个写入到一个大文件中.注意到IP是32位的,最多有个2^32个IP.同样可以采用映射的方法 ...

  5. 树莓派 Learning 002 装机后必要的操作 --- 08 实现PC端 远程登入 树莓派 --- 法2 远程登录树莓派的图形桌面

    树莓派 装机后必要的操作 - 实现PC端 远程登入 树莓派 我的树莓派型号:Raspberry Pi 2 Model B V1.1 装机系统:NOOBS v1.9.2 PC端系统:win10 x64 ...

  6. 4、在线blast比对结果解析(保守结构域)

    转载:http://www.bio1000.com/experiment/fenzi/237846.html 标签: NCBI Blast LASTP 摘要 : NCBI BLAST比对结果报告分析: ...

  7. sklearn常用数据的使用

    from sklearn import datasets from sklearn.linear_model import LinearRegression #加载数据 loaded_data = d ...

  8. 23. CTF综合靶机渗透(十六)

    靶机说明: VM Name: JIS-CTF : VulnUpload Difficulty: Beginner Description: There are five flags on this m ...

  9. Win10不能直接拖文件/Foxmail不能拖文件解决办法

    在桌面新建一个文本文档   打开文本文档复制下面的文字然后保存. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\M ...

  10. poj 1741 Tree(树的点分治)

    poj 1741 Tree(树的点分治) 给出一个n个结点的树和一个整数k,问有多少个距离不超过k的点对. 首先对于一个树中的点对,要么经过根结点,要么不经过.所以我们可以把经过根节点的符合点对统计出 ...