后台
if e.CommandName = "select" then
DataList1.SelectedIndex = e.Item.ItemIndex
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(".") & "/db1.mdb")
Dim objAdapter1 As New OleDbDataAdapter("select * from guestbook", objConn)
Dim objAdapter2 As New OleDbDataAdapter("select * from message", objConn)
Dim ds As New DataSet
objAdapter1.fill(ds, "guestbook")
objAdapter2.fill(ds, "message")
ds.Relations.Add("myrelations", ds.Tables("guestbook").Columns("id"), ds.Tables("message").Columns("id_reply"),False)
DataList1.DataSource = ds.Tables("guestbook").DefaultView
DataList1.EditItemIndex = -1
DataList1.DataBind()
end if
子datalist
<asp:datalist id=datalist1 Runat=Server DataSource='<%# Ctype(Container.DataItem,DataRowView).CreateChildView("myrelations") %>' >
<itemtemplate>
<%#DataBinder.Eval(Container.DataItem, "id_reply")%>
<%#DataBinder.Eval(Container.DataItem, "title")%>
</itemtemplate>
</asp:datalist>
注意问题:
id 和id_reply的值必须相等,,,而且id和id_reply的数据类型必须相同,如必须全是数字型