上一篇:用反射调用别人的.NET程序里的类和方法 >>
DataView如何绑定Web Service返回的主从表数据集
Microsoft® Office FrontPage® 2003
Author: Ben
MSN: benjamine65@hotmail.com
如何使用DataView调用XML Web Services
如何显示父子从表
l 设计目标:
Data View绑定Web Service返回的数据集, 显示父表, 同时以父表当前记录关联字估为条件, 嵌套显示子表
l 数据结构(以下例子以Sql Server 2000的Northwind示例数据库作例子):
l 样例Web Service:
如有: http://localhost/AspNetSample/Service1.asmx Web Services, 其中关键代码如:
[WebMethod]
public DataSet GetDataSource(string TableName)
{
DataSet ds = new DataSet("DataSetTables");
DataTable dt = new DataTable();
DataTable dtCus = new DataTable();
//sql
dt = SqlHelper.ExecuteDataset(ConnectionString, CommandType.Text, "select top 100 * from Orders").Tables[0];
dt.TableName = TableName;
dtCus = SqlHelper.ExecuteDataset(ConnectionString, CommandType.Text, "select top 100 * from Customers").Tables[0];
dtCus.TableName = "Customers";
ds.Tables.Add(dt.Copy());
ds.Tables.Add(dtCus.Copy());
return ds;
}
l 利用FrontPage 2003添加Data Source Catalog:
1. 打开Task Pane. 下拉菜单View -> Task Pane或Shortcut key Ctrl+F1 , 在Task Pane选择Data Source Catalog, 展开XML Web Services并点击Add to Catalog…
2. 在弹出的Data Source Properties窗口, 填General页内容, 给当前数据源起个名字, 例如: GetDataSource; 填Source页内容, Service Description Location为http://localhost/AspNetSample/Service1.asmx?WSDL, OK后就Connect Now! 如果Web Services设置正确, 则在Connection Info里会显示相关的Service Name, Operation 等, 我们现在在Operation选GetDataSource, 设置一下GetDataSource的接口参数; 最后要设置的是Login页的Login方法. 完成后就OK, XML Web Services下就会出现GetDataSource的图标
3. 将GetDataSource拖到页面的一个Web Part Zone内
4. 自定义Data View.
4.1. 插入一列, 并将光标置于新增列的单元格内. 再转换到Data View的Data View Details面板, 并选中Customers节点, 再Insert Subview
4.2. 设置关联关系. 此时Customers的记录会在显示Orders记录的Data View的那个新增的列内全部显示出来, 还未会根据CustomerID显示关联的Customer记录
所以现在要通过修改Data View 的XSL来实现关联过滤.
分析:
点选Data View GetDataSource, 切换到Code 视图, 找到关键的 XSL 语句, 如:
由此可以看出子表Customers是定义成一个xsl:template name=”dvt_2” 的, 我可以将CustomerID作为xsl:param传递到xsl:template里作为过滤条件
1) 添加xsl:param
修改<xsl:call-template name="dvt_2"/> 为如下:
<xsl:call-template name="dvt_2">
<xsl: with-param name="CustomerID" select="CustomerID"/>
</xsl:call-template>
查找dvt_2 template定义:
<xsl:template name="dvt_2">
<xsl:variable name="StyleName">Table</xsl:variable>
添加xsl:param:
<xsl:template name="dvt_2">
<xsl:param name="CustomerID"/>
<xsl:variable name="StyleName">Table</xsl:variable>
2) 应用xsl:param并实现过滤
将<xsl:template name="dvt_2">
<xsl:param name="CustomerID"/>
<xsl:variable name="StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="../Customers"/>
修改成:
<xsl:template name="dvt_2">
<xsl:param name="CustomerID"/>
<xsl:variable name="StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="../Customers[normalize-space(CustomerID) = $CustomerID]"/>
下一篇:在类中添加断言 >>
相关文章:
- · 鼠标下浮动的文字和时钟
- · 音乐城堡2004免费版
- · ASP汉字转拼音函数
- · Oracle常見問題集(四)
- · 以ASP实现数据查询及输入
- · ASP操作Excel技术总结
- · bak文件带来的灾难
- · 关于输入框中显示双引号和单引号
- · 关于&运算符效率低下的问题,好的解决办法
- · 右键失效
- · 显示用户是否在线的方法
- · 图片的导入导出
- · 取消缓存
- · n 行n列的显示数据
- · 转换十进制为二进制的函数
- · 随心所欲的定制“弹出窗口”
- · Duwamish深入剖析-结构篇
- · 如何实现无刷新的DropdownList联动效果
- · 交叉表应用-成绩统计
- · http1.1状态代码及其说明
- · 超级ASP大分页_我的类容我做主
- · 为TextBox增加隐藏属性,Value属性
- · 在网页中添加一个音乐对象
- · 每刷新一次就换一次图片的代码
- · 用ASP发送信使服务
- · asp.net 2.0有感-2.0的变化(2)
- · asp.net 2.0有感-2.0的变化(1)
- · Asp深度揭密(下)
- · Asp深度揭密(上)
- · 将数字转换成大写的金额换算函数
- · asp.net 2.0中用GRIDVIEW插入新记录
- · 农历与西历对照
- · 学习笔记(7.8) -- 对服务器控件应用样式
- · 无刷新聊天室(短信陪聊程序)
- · popup的两种方法
- · 一些js例子
- · 在js和cs中的排序
- · 教你一次下载网页中的所有资源
