📄 datalistform.aspx.vb
字号:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents DACategories As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents DAProductsInCategory As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents SqlSelectCommand2 As System.Data.SqlClient.SqlCommand
Protected WithEvents DsCategories1 As ProductsPerCategory.DSCategories
Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents bttnSeect As System.Web.UI.WebControls.Button
Protected WithEvents bttnSelect As System.Web.UI.WebControls.Button
Protected WithEvents DsProducts1 As ProductsPerCategory.DSProducts
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
Me.SqlSelectCommand2 = New System.Data.SqlClient.SqlCommand()
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
Me.DAProductsInCategory = New System.Data.SqlClient.SqlDataAdapter()
Me.DACategories = New System.Data.SqlClient.SqlDataAdapter()
Me.DsProducts1 = New ProductsPerCategory.DSProducts()
Me.DsCategories1 = New ProductsPerCategory.DSCategories()
CType(Me.DsProducts1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DsCategories1, System.ComponentModel.ISupportInitialize).BeginInit()
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=(local);initial catalog=Northwind;persist security info=False;user id" & _
"=sa;workstation id=PROTSERVER;packet size=4096"
'
'SqlSelectCommand2
'
Me.SqlSelectCommand2.CommandText = "SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice FROM dbo.Products WHERE" & _
" (CategoryID = @CatID)"
Me.SqlSelectCommand2.Connection = Me.SqlConnection1
Me.SqlSelectCommand2.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CatID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, True, CType(0, Byte), CType(0, Byte), "CategoryID", System.Data.DataRowVersion.Current, Nothing))
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT CategoryID, CategoryName, Description FROM dbo.Categories"
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'DAProductsInCategory
'
Me.DAProductsInCategory.SelectCommand = Me.SqlSelectCommand2
Me.DAProductsInCategory.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Products", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ProductID", "ProductID"), New System.Data.Common.DataColumnMapping("ProductName", "ProductName"), New System.Data.Common.DataColumnMapping("QuantityPerUnit", "QuantityPerUnit"), New System.Data.Common.DataColumnMapping("UnitPrice", "UnitPrice")})})
'
'DACategories
'
Me.DACategories.SelectCommand = Me.SqlSelectCommand1
Me.DACategories.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Categories", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("CategoryID", "CategoryID"), New System.Data.Common.DataColumnMapping("CategoryName", "CategoryName"), New System.Data.Common.DataColumnMapping("Description", "Description")})})
'
'DsProducts1
'
Me.DsProducts1.DataSetName = "DSProducts"
Me.DsProducts1.Locale = New System.Globalization.CultureInfo("en-US")
Me.DsProducts1.Namespace = "http://www.tempuri.org/DSProducts.xsd"
'
'DsCategories1
'
Me.DsCategories1.DataSetName = "DSCategories"
Me.DsCategories1.Locale = New System.Globalization.CultureInfo("en-US")
Me.DsCategories1.Namespace = "http://www.tempuri.org/DSCategories.xsd"
CType(Me.DsProducts1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DsCategories1, System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Me.IsPostBack Then
DACategories.Fill(DsCategories1)
DropDownList1.DataBind()
End If
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
DAProductsInCategory.SelectCommand.Parameters("@catID").Value = DropDownList1.SelectedItem.Value
DAProductsInCategory.Fill(DsProducts1)
DataList1.DataBind()
End Sub
Private Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
Dim itm As Integer
itm = e.Item.ItemIndex()
Dim keys As DataKeyCollection
keys = DataList1.DataKeys()
Label1.Text = "SELECTED ID = " & keys(itm).ToString
End Sub
Private Sub DataList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -