Asp.net Dynamic Data之三改变编辑和操作数据的现实方式
Asp.net Dynamic Data之三改变编辑和操作数据的现实方式
本专题介绍如何运用RouteCollection 添加或是修改Routing URL规则实现对页面的控制.
默认情况下
从Global.asax代码中我们不难看出它的规则{Table}/{action}.aspx,action=List,Detail,Edit,Insert,那么一定存在List.aspx,Detail.aspx,Edit.aspx,Insert.aspx的web page,表示不同的表的CRUD操作对应不同的页面;
// The following statement supports separate-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using separate pages. To enable this mode, uncomment the following
// route definition, and comment out the route definitions in the combined-page mode section that follows.
routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
{
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = model
});
// The following statements support combined-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using the same page. To enable this mode, uncomment the
// following routes and comment out the route definition in the separate-page mode section above.
//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
//{
// Action = PageAction.List,
// ViewName = "ListDetails",
// Model = model
//});
//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
//{
// Action = PageAction.Details,
// ViewName = "ListDetails",
// Model = model
//});
页面模板如下
提供了上述定义的{action}.aspx
显示的效果
页面部分的代码
注意看NavigateUrl的属性,通过GetActionPath动态获取Url,具体的用法我们后面再说明
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
AllowPaging="True" AllowSorting="True" CssClass="gridview">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="EditHyperLink" runat="server"
NavigateUrl='<%# table.GetActionPath(PageAction.Edit, GetDataItem()) %>'
Text="Edit" /> <asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete"
CausesValidation="false" Text="Delete"
OnClientClick='return confirm("Are you sure you want to delete this item?");'
/> <asp:HyperLink ID="DetailsHyperLink" runat="server"
NavigateUrl='<%# table.GetActionPath(PageAction.Details, GetDataItem()) %>'
Text="Details" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="footer"/>
<PagerTemplate>
<asp:GridViewPager runat="server" />
</PagerTemplate>
<EmptyDataTemplate>
There are currently no items in this table.
</EmptyDataTemplate>
</asp:GridView>
改变一下编辑方式
希望修改/新增/显示(Edit,Insert,List,Detail)在一个页面里面完成,那我们需要怎么做呢;
修改一下Global.asax下的代码,注解掉上的语句,恢复下面的,URL的规则变成{table}/ListDetails.aspx,所有的操作将在同一个页面中完成;
// The following statement supports separate-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using separate pages. To enable this mode, uncomment the following
// route definition, and comment out the route definitions in the combined-page mode section that follows.
//routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
//{
// Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
// Model = model
//});
// The following statements support combined-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using the same page. To enable this mode, uncomment the
// following routes and comment out the route definition in the separate-page mode section above.
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
{
Action = PageAction.List,
ViewName = "ListDetails",
Model = model
});
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
{
Action = PageAction.Details,
ViewName = "ListDetails",
Model = model
});
显示的效果
对一个表的操作都在同一个页面中完成;
页面部分的代码
这里我们看不到GetActionPath的方法了,完全按照通常的处理方式作了
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
AutoGenerateSelectButton="True" AutoGenerateEditButton="True" AutoGenerateDeleteButton="true"
AllowPaging="True" AllowSorting="True" OnDataBound="OnGridViewDataBound"
OnRowEditing="OnGridViewRowEditing" OnSelectedIndexChanging="OnGridViewSelectedIndexChanging"
OnRowDeleted="OnGridViewRowDeleted" OnRowUpdated="OnGridViewRowUpdated"
OnRowCreated="OnGridViewRowCreated" CssClass="gridview">
<PagerStyle CssClass="footer" />
<SelectedRowStyle CssClass="selected" />
<PagerTemplate>
<asp:GridViewPager runat="server" />
</PagerTemplate>
<EmptyDataTemplate>
There are currently no items in this table.
</EmptyDataTemplate>
</asp:GridView>
更加灵活的方式
我要实现对Products表的操作分在不同的页面,而像Categories表字段少的就在一个页面里做;
修改一下Global.asax下的代码,Url规则Products/{action}.aspx,Table="Products"。
// The following statement supports separate-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using separate pages. To enable this mode, uncomment the following
// route definition, and comment out the route definitions in the combined-page mode section that follows.
routes.Add(new DynamicDataRoute("Products/{action}.aspx")
{
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Table="Products",
Model = model
});
// The following statements support combined-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using the same page. To enable this mode, uncomment the
// following routes and comment out the route definition in the separate-page mode section above.
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
{
Action = PageAction.List,
ViewName = "ListDetails",
Model = model
});
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
{
Action = PageAction.Details,
ViewName = "ListDetails",
Model = model
});
下期将如何改变字段的现实/编辑方式,可以是Rich_Text,Date_Edit,Number
Asp.net Dynamic Data之三改变编辑和操作数据的现实方式相关推荐
- 动态数据交换(DDE, Dynamic Data Exchange)简介
动态数据交换(DDE, Dynamic Data Exchange)简介 1.简介 DDE是一种动态数据交换机制(Dynamic Data Exchange,DDE).使用DDE通讯需要两个W ...
- ASP.NET 2.0中改变passwordrecovery发邮件时的信息
ASP.NET 2.0中改变passwordrecovery发邮件时的信息 在ASP.NET 2.0的登陆控件中(详细见我的文章,www.yesky.com/SoftChannel/723423804 ...
- Dynamic 365 子网格编辑控制列可编辑
Dynamic 365 子网格编辑控制列可编辑 DOCS告诉我们了怎么配置子网格编辑,直接上链接,这里就不阐述了. 链接 我今天的重点是,咱们在项目中,肯定会遇到这种需求,在特定的单据状态下,允许编辑 ...
- [习题]综合练习 -- SqlDataSource精灵就能完成,[山寨版] Dynamic Data WebSite
这是我的文章备份,有空请到我的网站走走, http://www.dotblogs.com.tw/mis2000lab/ 才能掌握我提供的第一手信息,谢谢您. http://www.dotblogs ...
- SQL Server 动态数据掩藏(Dynamic Data Masking)探索和实施
动态数据掩藏(DDM) 是SQL Server 2016 CTP 2.1引入的新功能 数据库加密技术本质上改变了数据存储结构,而DDM只是在返回客户端的时候对数据进行隐藏.sysadmin的成员登陆账 ...
- Azure SQL Database (23) Azure SQL Database Dynamic Data Masking动态数据掩码
<Windows Azure Platform 系列文章目录> 我们在使用关系型数据的时候,有时候希望: - 管理员admin,可以查看到所有的数据 - 普通用户,某些敏感字段,比如信用卡 ...
- Dynamic Data Web Application编译是报GetActionPath调用模糊解决办法
新建的Dynamic Data Web Application编译时报错 Error 3 The call is ambiguous between the following methods or ...
- 集群环境下,你不得不注意的ASP.NET Core Data Protection 机制
引言 最近线上环境遇到一个问题,就是ASP.NET Core Web应用在单个容器使用正常,扩展多个容器无法访问的问题.查看容器日志,发现以下异常: System.Security.Cryptogra ...
- LyX使用小记之三 公式编辑
LyX使用小记之三 公式编辑 在LyX中可以方便的插入公式,只需要点击Insert Math按钮或者Ctrl+M即可,也可以在Insert->math中选择要插入的公式类型进行插入 在进行公式编 ...
最新文章
- java api 框架_java常用对象API之集合框架
- 【spring 5】AOP:spring中对于AOP的的实现
- 我也说说Emacs吧(6) - Lisp速成
- 菜鸟解读qt源码----qsqlfield.h
- Springsecurity之AccessDecisionManager
- 最简单的分形图像生成算法
- JavaScript基础11-day13【正则表达式(量词、语法、转义字符、元字符)、DOM(节点、事件)、图片切换】
- C# 面向对象三大特性:封装、继承、多态
- iOS开发UI篇—懒载入
- 填问卷,得《2015中国呼叫中心知识库现状与问题报告》
- DataGridView直接导出EXCEL
- 简单粗暴,快速入门Python
- P7 P8:训练神经网络
- 日本要向中国收二维码使用费?每人一分钱?
- 拷贝网页内容增加版权信息的 JavaScript 代码示例
- Ubuntu各版本下载安装知网论文阅读神器CAJViewer,并添加快捷图标启动方式
- python 水晶报表_VS2010中水晶报表应用及实例
- vue2知识点:数据代理
- PAT练习 蜜蜂寻路
- Drat语法概览(一)