Ch16-05-01.aspx 使用DataList控件显示记录
' 在这里设置联机字符串的内容
Sub Page_Load(Obj As Object, e As EventArgs)
If Not IsPostBack Then
GetDataSource()
End If
End Sub
Sub GetDataSource()
Dim DSN As String
Dim tSQL As String = "Select * From UserDatas"
Dim OBJConn As OleDbConnection
DSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/ASP/chap14/ASP.NET网页数据库.mdb") & ";"
OBJConn = New OleDbConnection(DSN)
OBJConn.Open()
Dim OBJCmd As OleDbCommand = New OleDbCommand(tSQL, OBJConn)
DataListCTL.DataSource = OBJCmd.ExecuteReader()
DataListCTL.DataBind()
OBJConn.Close()
End Sub
Sub DataList_ItemCommand(Obj As Object, E As DataListCommandEventArgs)
DataListCTL.SelectedIndex = E.Item.ItemIndex
Label1.Text = "用户编号:" & _
DataListCTL.DataKeys.Item(E.Item.ItemIndex).ToString()
GetDataSource()
End Sub
使用DataList控件显示记录
HeaderStyle-BackColor = "#80F0F0"
SelectedItemStyle-BackColor = "#4040FF"
SelectedItemStyle-ForeColor = "#FFFF00"
GridLines = "Both"
RepeatLayoyut = "Table"
RepeatColumns = "5"
RepeatDirection = "Vertical"
DataKeyField = "UID"
OnItemCommand = "DataList_ItemCommand">
单击用户姓名即可显示详细数据
Text=''
CommandName = "UserSelected" />