こんにちは、こだかです。
前回に引き続き、Jasperの実装を確認してみましょう。今回はVBでAutomatic UI Bindingをご紹介します。
まずはソースコードを見て下さい。Default.aspx--------------------------------------------------------------------<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewPage.aspx.vb" Inherits="GridViewPage" %>
<%@ Register Assembly="Microsoft.Jasper.CTP" Namespace="Microsoft.Jasper.Web" TagPrefix="jasper" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Demonstrate Building Web UI with Project Jasper using a GridView control</title></head><body> <form id="form1" runat="server"> <asp:GridView ID="Products" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AllowPaging="True"> </asp:GridView> <jasper:AutoDataSource ID="AutoDataSource1" runat="server"> </jasper:AutoDataSource> </form></body></html>
Default.aspx.vb-----------------------------------------------------------------Imports Microsoft.Jasper
Partial Class GridViewPage Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load AutoDataSource1.DynamicContext = GetDynamicContext() End Sub
Private Function GetDynamicContext() As DynamicContext Dim context As DynamicContext = Session("DynamicContext") If context Is Nothing Then Dim connectionString As String =接続文字 context = DynamicContext.CreateDynamicContext(connectionString) End If Return context End FunctionEnd Class
これだけです。ビルドしてみましょう。
データがバインドされて表示されています。どこで、バインドの定義をしているのでしょう?実はコントロール名がテーブル名になっているのです。つまり今回の場合は、GridView ID="Products"ですので、Productsテーブルが表示されています、何か変な感じですね。追加、更新、削除も可能です。
ちなみにProductsテーブルとCategoriesテーブルは以下の様な関連を持っています。
この場合、コントロール名をCategories_Products(明細側)とするだけで、ヘッダ/明細形式のバインディングが可能になります。
前回のIronPythonと同じく、サンプルは"%ProgramFiles%\Microsoft Codename Jasper CTP\Samples"の下にありますので、興味のある方はご確認頂ければと思います。
こだかたろう