Ashx增删改查_动软
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增删改查_动软的更多相关文章
- SSM整合_年轻人的第一个增删改查_基础环境搭建
写在前面 SSM整合_年轻人的第一个增删改查_基础环境搭建 SSM整合_年轻人的第一个增删改查_查找 SSM整合_年轻人的第一个增删改查_新增 SSM整合_年轻人的第一个增删改查_修改 SSM整合_年 ...
- SSM整合_年轻人的第一个增删改查_查找
写在前面 SSM整合_年轻人的第一个增删改查_基础环境搭建 SSM整合_年轻人的第一个增删改查_查找 SSM整合_年轻人的第一个增删改查_新增 SSM整合_年轻人的第一个增删改查_修改 SSM整合_年 ...
- SSM整合_年轻人的第一个增删改查_新增
写在前面 SSM整合_年轻人的第一个增删改查_基础环境搭建 SSM整合_年轻人的第一个增删改查_查找 SSM整合_年轻人的第一个增删改查_新增 SSM整合_年轻人的第一个增删改查_修改 SSM整合_年 ...
- Oracle学习总结_day01_day02_表的创建_增删改查_约束
本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 更新: SELECT * FROM (SELECT R ...
- 论坛模块_版块管理_增删改查&实现上下移动
论坛模块_版块管理1_增删改查 设计实体Forum.java public class Forum { private Long id; private String name; private St ...
- 1.SSM整合_单表的增删改查
目标:增删改查 环境:Maven+Eclipse+Tomcat7+JDK7 思维导图: 表结构 目录结构 依赖 <dependencies> <dependency> < ...
- Django基础学习四_数据库的增删改查
今天主要学习两个东西 1.如何对数据库做增删改查 2.如果将数据库中的数据用html的方式返回到前台 一.对数据库中增删改查操作 1.首先需要先见表,见表的方法我们在“http://www.cnblo ...
- 玩下软工项目,第一轮--全局Context的获取,SQLite的建立与增删改查,读取用户通话记录信息
项目的Github地址:https://github.com/ggrcwxh/LastTime 采用基于git的多人协作开发模式 软件采用mvc设计模式,前端这么艺术的事我不太懂,交给斌豪同学去头疼了 ...
- Hibernate入门_增删改查
一.Hibernate入门案例剖析: ①创建实体类Student 并重写toString方法 public class Student { private Integer sid; private ...
随机推荐
- linux日常管理-rsync常用选项详解
-av 同步目录 写法 123/ /tmp/333/ 意思是把123下的文件同步到/tmp/333/下 结尾不加/ 只同步目录 两个目录一样的. //////////////////////// ...
- mysql主从服务器复制原理
在实际企业应用环境当中,单台mysql数据库是不足以满足日后业务需求的.譬如服务器发生故障,没有备份服务器来提供服务的话,业务就得停止.介于这种情况,我们来学习一下mysql主从复制. 将Mysql的 ...
- AngularJS(Part 10)--页面导航
页面导航 过去,一个URL代表一个页面.但是随着Ajax的兴起,情况发生的很大的变化.不同的内容可以使用同一个URL.这让浏览器中的回退.前进甚至收藏按钮都失去了作用.而AngularJS提供 ...
- 5、bam格式转为bigwig格式
1.Bam2bigwig(工具) https://www.researchgate.net/publication/301292288_Bam2bigwig_a_tool_to_convert_bam ...
- 卡特兰数&错排&一个一直记不住的公式
卡特兰数 公式:f(x)=f(2)*f(x-1)+f(3)*f(x-2)+......+f(x-1)*f(2) #include<iostream>#include<cstdlib& ...
- JavaScript: 高级技巧: window 对象也可以添加自定义属性
JavaScript: 高级技巧: window 对象也可以添加自定义属性 例如 window.ntName = 'a';例如 window.ntXw = top; 优点是, window 无须等加载 ...
- SQL Server中通过设置非聚集索引(Non-Clustered index)来达到性能优化的目的
首先我们一下,在SQL Server 2014 Management Studio中,如何为一张表设置Non-Clustered index 具体可以参考 https://docs.microsof ...
- 使用form 组件写一个用户注册,并用 bootstrap渲染
需求:使用form组件,写一个用户注册系统,包含用户名, 密码, 确认密码,手机号,性别,爱好,注册.并用bootsrap渲染,成果如下: 首先创建一个django 项目.然后在连接pymysql数据 ...
- 服务器控件button点击时执行脚本弹出提示对话框Button2.Attributes.Add("onclick","事件")
<HTML> <HEAD> <title>**********资料更新</title> <meta content="Microso ...
- Dapper 存储过程、事务等
接上一篇<Dapper 增删改查> 0.存储过程 create proc p_login ), ), ) output as begin if(exists(select * from U ...