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. js 面向对象代码

    贴上一段同事写的代码,值的纪念 <script type="text/javascript"> //创建箱子类 function Box(option) { var s ...

  2. k8s 基础 pod操作

    创建hell world pod #vim hello-world-pod.yaml apiVersion: v1 kind: Pod metadata: name: hello-world spec ...

  3. redis的 key string hash list set sorted set 常用的方法

    redis 安装文件:  http://blog.csdn.net/tangsilai/article/details/7477961 ==============================   ...

  4. Angular06 组件、模块、父子组件之间的数据传递

    1 创建组件 进入到angular项目的根目录,执行如下命令 ng g component test-component 注意:执行完上述命令后在angular项目的src/app文件夹下就会多出一个 ...

  5. 31、SAM文件中flag含义解释工具--转载

    转载:http://www.cnblogs.com/nkwy2012/p/6362996.html  SAM是Sequence Alignment/Map 的缩写.像bwa等软件序列比对结果都会输出这 ...

  6. ARC097C K-th Substring

    传送门 题目 You are given a string s. Among the different substrings of s, print the K-th lexicographical ...

  7. linux 统计 程序 运行时间

    测试 代码运行时间 linux 中的 <sys/time.h> 中 有个函数可以获取当前时间,精确到 微秒 ---->  gettimeofday() #include <sy ...

  8. iOS开发中,修改ASIHTTPRequest源码,禁止在POST时URL编码

    通过ASIHTTPRequest库进行POST时,会对POST的文本内容进行encodeURL,而且ASIHTTPRequest自身并没有配置项可以关闭这个转换. 本文提供一个方法关闭encodeUR ...

  9. url中传中文

    function gotoPage(code,name){//name为中文 window.location.href="upload.jsp?bigCategoryCode="+ ...

  10. 4.XXE (XML External Entity Injection)

    XXE (XML External Entity Injection) 0x01 什么是XXE XML外部实体注入 若是PHP,libxml_disable_entity_loader设置为TRUE可 ...