DataView如何綁定Web Service返回的主從表資料集

來源:互聯網
上載者:User
web|資料 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]"/>





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.