8 1 Data Table Data Table Table 01

  • Slides: 71
Download presentation

8 -1 Data. Table 的資料結構

8 -1 Data. Table 的資料結構

Data. Table 的資料結構

Data. Table 的資料結構

Table 01. aspx Part I <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White">

Table 01. aspx Part I <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"> <H 3>Data. Table的建構:開啟資料庫<HR></H 3> <asp: Label runat="server" id="Msg" /><p> <HR></Body> </Html>

Table 01. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As

Table 01. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As Event. Args) Dim Table As System. Data. Table = Open. Mdb. Table( "Sample. mdb", "股票行情表" ) If Not Table Is Nothing Then Msg. Text = "已經建構好 Data. Table!" End If End Sub </script>

Table 02. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Table 02. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"> <H 3>Data. Table的建構:開啟資料庫<HR></H 3> <asp: Label runat="server" id="Msg" /><p> <HR></Body> </Html>

Table 02. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As

Table 02. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As Event. Args) Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "股票行情表" ) If Not Table Is Nothing Then Msg. Text = "已經建構好 Data. Table!" End If End Sub </script>

Table 03. aspx 節錄 Part I, II ' Part 1: 宣告並且建立 Data. Table 物件

Table 03. aspx 節錄 Part I, II ' Part 1: 宣告並且建立 Data. Table 物件 Dim Table As New Data. Table ' Part 2: 建立欄位 Table. Columns. Add(New Data. Column("姓名", Get. Type(String))) Table. Columns. Add(New Data. Column("國文", Get. Type(Integer))) Table. Columns. Add(New Data. Column("英文", Get. Type(Integer))) Table. Columns. Add(New Data. Column("數學", Get. Type(Integer)))

Table 03. aspx 節錄 Part III ' Part 3: 加入資料列 For I = 0

Table 03. aspx 節錄 Part III ' Part 3: 加入資料列 For I = 0 To UBound(姓名) Dim Row As Data. Row = Table. New. Row() Row("姓名") = 姓名(I) Row("國文") = 國文(I) Row("英文") = 英文(I) Row("數學") = 數學(I) Table. Rows. Add(Row) Next

8 -2 Data. Grid 初體驗

8 -2 Data. Grid 初體驗

Grid 01. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Grid 01. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Grid 01. aspx -- 用 Data. Grid 顯示 Data. Table 的資料<HR></H 3> <asp: Data. Grid runat="server" id="My. Grid" /> <p> <HR></Center></Body> </Html>

Grid 01. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As

Grid 01. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As Event. Args) Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "股票行情表" ) ' Data. Grid 與 Data. Table 的資料繫結 My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Grid 03. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Grid 03. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Grid 03. aspx -- 設定Data. Grid的外觀<HR></H 3> <asp: Data. Grid runat="server" id="My. Grid" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0" /> <p> <HR></Center></Body> </Html>

Grid 03. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As

Grid 03. aspx Part II <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As Event. Args) Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) ' Data. Grid 與 Data. Table 的資料繫結 My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub </script>

Grid 04. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Grid 04. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Grid 04. aspx -- 分頁瀏覽的基礎<HR></H 3> <Form runat="server"> <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page. Size="10" On. Page. Index. Changed="Change. Page" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0" /> </Form>

Grid 04. aspx Part II <p> <HR></Center></Body> </Html> <script Language="VB" runat="server"> Sub Page_Load(sender As

Grid 04. aspx Part II <p> <HR></Center></Body> </Html> <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As Event. Args) Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Grid 04. aspx Part III Sub Change. Page(sender As Object, e As Data. Grid.

Grid 04. aspx Part III Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub </script>

利用 Is. Post. Back 解決執行效能 問題 (Grid 04 b. aspx 節錄) Sub Page_Load(sender As

利用 Is. Post. Back 解決執行效能 問題 (Grid 04 b. aspx 節錄) Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then ' 網頁第一次被瀏覽 Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End If End Sub

Grid 04 c. aspx 節錄 Part I <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind.

Grid 04 c. aspx 節錄 Part I <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Grid 04 c. aspx 節錄 Part II Sub Page_Load(sender As Object, e As Event.

Grid 04 c. aspx 節錄 Part II Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then Open. Data. Base_And_Bind. To. Data. Grid() End If End Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Open. Data. Base_And_Bind. To. Data. Grid() End Sub </script>

Grid 05. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Grid 05. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"> <H 3>Grid 05. aspx -- 將 < 及 > 改成「上一頁」及「下一頁」<HR></H 3> <Form runat="server"> <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page. Size="10" On. Page. Index. Changed="Change. Page"

Grid 05. aspx Part II Pager. Style-Horizontal. Align="Right" Pager. Style-Next. Page. Text="下一頁" Pager. Style-Prev.

Grid 05. aspx Part II Pager. Style-Horizontal. Align="Right" Pager. Style-Next. Page. Text="下一頁" Pager. Style-Prev. Page. Text="上一頁" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0" /> </Form> <p> <HR></Center></Body> </Html>

Grid 05. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data.

Grid 05. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Grid 05. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If

Grid 05. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then Open. Data. Base_And_Bind. To. Data. Grid() End If End Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Open. Data. Base_And_Bind. To. Data. Grid() End Sub </script>

Grid 06. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Grid 06. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Grid 06. aspx -- 將 < 及 > 改成 1 2 3 4 … 的頁次連結<HR></H 3> <Form runat="server"> <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page. Size="10" On. Page. Index. Changed="Change. Page"

Grid 06. aspx Part II Pager. Style-Mode="Numeric. Pages" Pager. Style-Horizontal. Align="Right" Header. Style-Back. Color="#AAAADD"

Grid 06. aspx Part II Pager. Style-Mode="Numeric. Pages" Pager. Style-Horizontal. Align="Right" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0" /> </Form> <p> <HR></Center></Body> </Html>

Grid 06. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data.

Grid 06. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "股票行情表" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Grid 06. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If

Grid 06. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then Open. Data. Base_And_Bind. To. Data. Grid() End If End Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Open. Data. Base_And_Bind. To. Data. Grid() End Sub </script>

8 -4 Data. Grid 與欄位設定

8 -4 Data. Grid 與欄位設定

Grid 07. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Grid 07. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Grid 07. aspx -- 自定欄位抬頭及對齊方式<HR></H 3> <Form runat="server"> <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page. Size="10" On. Page. Index. Changed="Change. Page" Pager. Style-Horizontal. Align="Right" Pager. Style-Next. Page. Text="下一頁" Pager. Style-Prev. Page. Text="上一頁" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0"

Grid 07. aspx Part II Auto. Generate. Columns="false" > <Columns> <asp: Bound. Column Data.

Grid 07. aspx Part II Auto. Generate. Columns="false" > <Columns> <asp: Bound. Column Data. Field="學號" Header. Text="學號" /> <asp: Bound. Column Data. Field="姓名" Header. Text="姓名" /> <asp: Bound. Column Data. Field="國文" Header. Text="國語" Item. Style-Horizontal. Align="right"/> <asp: Bound. Column Data. Field="英文" Header. Text="英語" Item. Style-Horizontal. Align="right"/> <asp: Bound. Column Data. Field="數學" Header. Text="數學" Item. Style-Horizontal. Align="right"/> </Columns> </asp: Data. Grid> </Form> <p> <HR></Center></Body> </Html>

Grid 07. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data.

Grid 07. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Grid 07. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If

Grid 07. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then Open. Data. Base_And_Bind. To. Data. Grid() End If End Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Open. Data. Base_And_Bind. To. Data. Grid() End Sub </script>

Grid 08. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Grid 08. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Grid 08. aspx -- 設定 Data. Grid 欄位的連結<HR></H 3> <Form runat="server"> <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page. Size="10" On. Page. Index. Changed="Change. Page" Pager. Style-Horizontal. Align="Right" Pager. Style-Next. Page. Text=“下一頁” Pager. Style-Prev. Page. Text="上一頁" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0" Auto. Generate. Columns="false" >

Grid 08. aspx Part II <Columns> <asp: Hyper. Link. Column Data. Text. Field="學號" Header.

Grid 08. aspx Part II <Columns> <asp: Hyper. Link. Column Data. Text. Field="學號" Header. Text="學號" Data. Navigate. Url. Field="學號" Data. Navigate. Url. Format. String="students. aspx? id={0}" Target="_blank" /> <asp: Bound. Column Data. Field="姓名" Header. Text="姓名" /> <asp: Bound. Column Data. Field="國文" Header. Text="國語" Item. Style-Horizontal. Align="right"/> <asp: Bound. Column Data. Field="英文" Header. Text="英語" Item. Style-Horizontal. Align="right"/> <asp: Bound. Column Data. Field="數學" Header. Text="數學" Item. Style-Horizontal. Align="right"/> </Columns> </asp: Data. Grid> </Form> <p> <HR></Center></Body> </Html>

Grid 08. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data.

Grid 08. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Grid 08. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If

Grid 08. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then Open. Data. Base_And_Bind. To. Data. Grid() End If End Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Open. Data. Base_And_Bind. To. Data. Grid() End Sub </script>

8 -5 Data. Table 與排序

8 -5 Data. Table 與排序

Sort 01. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Sort 01. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Sort 01. aspx -- Sort 屬性與資料排序<HR></H 3> <Form runat="server"> 選擇排序的欄位: <asp: List. Box runat="server" id="Sort. Field" Rows=1> <asp: List. Item Selected>學號</asp: List. Item> <asp: List. Item>姓名</asp: List. Item> <asp: List. Item>國文</asp: List. Item> <asp: List. Item>英文</asp: List. Item> <asp: List. Item>數學</asp: List. Item> </asp: List. Box> <asp: Button runat="server" Text="排序" On. Click="Sort. Page"/> <p>

Sort 01. aspx Part II <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page.

Sort 01. aspx Part II <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page. Size="10" On. Page. Index. Changed="Change. Page" Pager. Style-Horizontal. Align="Right" Pager. Style-Next. Page. Text="下一頁" Pager. Style-Prev. Page. Text="上一頁" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0" /><p> </Form> <HR></Center></Body> </Html>

Sort 01. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data.

Sort 01. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) Table. Default. View. Sort = Sort. Field. Selected. Item. Text My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Sort 01. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If

Sort 01. aspx Part IV Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then Open. Data. Base_And_Bind. To. Data. Grid() End If End Sub Sort. Page(sender As Object, e As Event. Args) Open. Data. Base_And_Bind. To. Data. Grid() End Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Open. Data. Base_And_Bind. To. Data. Grid() End Sub </script>

遞增排序或遞減排序 (3) n 新增 Radio. Button. List 控制元件,用以選 擇「遞增排序」或「遞減排序」: <asp: Radio. Button. List runat="server"

遞增排序或遞減排序 (3) n 新增 Radio. Button. List 控制元件,用以選 擇「遞增排序」或「遞減排序」: <asp: Radio. Button. List runat="server" id="Sort. Type" Repeat. Direction="Horizontal" Repeat. Columns="2"> <asp: List. Item Selected>遞增排序</asp: List. Item> <asp: List. Item>遞減排序</asp: List. Item> </asp: Radio. Button. List>

遞增排序或遞減排序 (4) n 修改 Open. Data. Base_And_Bind. To. Data. Grid() 副 程式,使成為: Sub Open.

遞增排序或遞減排序 (4) n 修改 Open. Data. Base_And_Bind. To. Data. Grid() 副 程式,使成為: Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) If Sort. Type. Selected. Item. Text = "遞減排序" Then Table. Default. View. Sort = Sort. Field. Selected. Item. Text & " Desc" Else Table. Default. View. Sort = Sort. Field. Selected. Item. Text End If My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub

Sort 03. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb"

Sort 03. aspx Part I <%@ Import Namespace="System. Data" %> <!-- #include File="Mdb. vb" --> <Html> <Body Bg. Color="White"><Center> <H 3>Sort 03. aspx -- 按下 Data. Grid 的抬頭以排序資料<HR></H 3> <Form runat="server"> <asp: Data. Grid runat="server" id="My. Grid" Allow. Paging="True" Page. Size="10" On. Page. Index. Changed="Change. Page" Pager. Style-Horizontal. Align="Right" Pager. Style-Next. Page. Text="下一頁" Pager. Style-Prev. Page. Text="上一頁"

Sort 03. aspx Part II Allow. Sorting="true" On. Sort. Command="Dg. Sort. Page" Header. Style-Back.

Sort 03. aspx Part II Allow. Sorting="true" On. Sort. Command="Dg. Sort. Page" Header. Style-Back. Color="#AAAADD" Alternating. Item. Style-Back. Color="#FFFFC 0" Border. Color="Black" Cell. Padding="2" Cell. Spacing="0" /><p> <asp: Label runat="server" id="Sort. Field" Text="學號" Visible="False" /> <asp: Label runat="server" id="Sort. Type" Text="" Visible="False" /> </Form> <HR></Center></Body> </Html>

Sort 03. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data.

Sort 03. aspx Part III <script Language="VB" runat="server"> Sub Open. Data. Base_And_Bind. To. Data. Grid() Dim Table As Data. Table = Open. Mdb. Table( "Sample. mdb", "成績單" ) Table. Default. View. Sort = Sort. Field. Text & Sort. Type. Text My. Grid. Data. Source = Table. Default. View My. Grid. Data. Bind() End Sub Page_Load(sender As Object, e As Event. Args) If Not Is. Post. Back Then Open. Data. Base_And_Bind. To. Data. Grid() End If End Sub

Sort 03. aspx Part IV Sub Dg. Sort. Page(sender As Object, e As Data.

Sort 03. aspx Part IV Sub Dg. Sort. Page(sender As Object, e As Data. Grid. Sort. Command. Event. Args) If Sort. Field. Text = e. Sort. Expression Then If Sort. Type. Text = "" Then Sort. Type. Text = " Desc" Else Sort. Type. Text = "" End If Else Sort. Field. Text = e. Sort. Expression Sort. Type. Text = "" End If Open. Data. Base_And_Bind. To. Data. Grid() End Sub Change. Page(sender As Object, e As Data. Grid. Page. Changed. Event. Args) My. Grid. Current. Page. Index = e. New. Page. Index Open. Data. Base_And_Bind. To. Data. Grid() End Sub </script>