📄 masterchild.vb
字号:
Imports System
Imports System.Collections
Imports System.Text
Imports System.Data
Imports System.Data.OleDb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class BaseClass
Inherits System.Web.UI.Page
Protected AuthorsGrid as DataGrid
protected titlesGrid as DataGrid
protected detailsPanel as Panel
Public currentAuthor as object
Dim myConnection As OleDbConnection
Dim myCommand As OleDbDataAdapter
Dim ds As New DataSet
Dim ConnStr As String
Dim SQL As String
Sub Page_Load(Source As Object, E As EventArgs)
ConnStr = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=pubs;User ID=sa;"
myConnection = New OleDbConnection(ConnStr)
if NOT (isPostBack)
rebind
end if
End Sub
Sub FillDs
sql = " select * , au_lname + ',' + au_fname as au_name"
sql = sql + " From authors a, titles t, titleauthor ta"
sql = sql + " Where a.au_id = ta.au_id AND t.title_id = ta.title_id"
myCommand = New OleDbDataAdapter(SQL, myConnection)
'use Fill method of DataSetCommand to populate dataset
myCommand.Fill(ds, "Authors")
end Sub
Sub ReBind()
FillDs
'Binding a Grid
AuthorsGrid.DataSource=ds.Tables("Authors").DefaultView
AuthorsGrid.DataBind()
End Sub
'
Sub Grid_Select(sender as Object , e as EventArgs)
Dim vIndex As Integer
Dim vkey as string
vIndex = AuthorsGrid.SelectedIndex
vkey =AuthorsGrid.DataKeys(vIndex).ToString
UpdateSelection(vkey)
end sub
Sub UpdateSelection(vkey as string)
Dim myConnection2 As OleDbConnection
Dim myCommand2 As OleDbDataAdapter
Dim ds2 As New DataSet
Dim ConnStr2 As String
Dim SQL2 As String
Dim itemcount As Integer
sql2 = " select * , au_lname + ',' + au_fname as au_name"
sql2 = sql2 + " From authors a, titles t, titleauthor ta"
sql2 = sql2 + " Where a.au_id = ta.au_id AND t.title_id = ta.title_id"
sql2 = sql2 + " AND a.au_id = '" + vkey + "'"
myCommand2 = New OleDbDataAdapter(SQL2, myConnection)
myCommand2.Fill(ds2, "Authors")
'Bind the Grid
titlesGrid.DataSource=ds2.Tables("Authors").DefaultView
titlesGrid.DataBind()
itemcount = titlesGrid.Items.Count
if itemcount >= 1 then
detailsPanel.Visible = true
Else
detailsPanel.Visible = false
response.write("No rows found")
end if
End sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -