日期:2010-05-08 浏览次数:20403 次
新建一个Web窗体,命名为DataTable_Simple.aspx,添加两个DropDownList控件,设计窗口如8.9所示。
图 8.9 DataTable_Simple.aspx的设计窗口
切换DataTable_Simple.aspx的HTML代码窗口,HTML代码如下:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DataTable_Simple.aspx.vb" Inherits="Adodotnet.DataTable_Simple"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>利用DataTable保存数据</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="360" border="1" style="WIDTH: 360px; HEIGHT: 75px">
<TR>
<TD align="center"><STRONG>利用DataTable保存数据</STRONG></TD>
</TR>
<TR>
<TD>第
<asp:DropDownList id="DropDownList1" runat="server" Width="107px" AutoPostBack="True"></asp:DropDownList>项的项值是-->
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList></TD>
</TR>
</TABLE>
</FONT>
</form>
</body>
</HTML>
查看DataTable_Simple.aspx的逻辑代码(即DataTable_Simple.aspx.vb文件),其中逻辑代码如下:
'--------cdoe begin----------
Public Class DataTable_Simple
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Page.IsPostBack Then
Dim mydt As DataTable
&