欢迎光临
我们一直在努力

DataView如何绑定Web Service返回的主从表数据集-ASP教程,ASP应用

建站超值云服务器,限时71元/月

working with the data view web part

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]"/>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » DataView如何绑定Web Service返回的主从表数据集-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章