zoukankan      html  css  js  c++  java
  • repeater显示主从表结构

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="MenuALL.aspx.vb" Inherits="eMeng.MenuALL" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>未命名頁面</title>
      
      
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
      
    <asp:repeater id="parentRepeater" runat="server">
    <itemtemplate>

          <%# DataBinder.Eval(Container.DataItem,"span") %>


        <asp:repeater id="childRepeater" runat="server" datasource='<%# Container.DataItem("myrelation") %>'>
          <itemtemplate>
            <%# DataBinder.Eval(Container.DataItem, "menu")%>
           
          </itemtemplate>
        </asp:repeater>

    </itemtemplate>
    </asp:repeater>

        </div>
        </form>
    </body>
    </html>

    Imports System
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Web
    Imports System.Web.SessionState
    Imports System.Web.UI
    Imports System.Web.UI.WebControls

    Namespace eMeng
      
        Public Class MenuALL
            Inherits System.Web.UI.Page
            'Dim parentRepeater As System.Web.UI.WebControls.Repeater

            Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
                '为Authors表创建 Connection 和 DataAdapter
                Dim cnnString As String = ConfigurationManager.ConnectionStrings("cnn").ConnectionString
                Dim cnn As New SqlConnection(cnnString)
                Dim cmd1 As New SqlDataAdapter("select * from c_MenuHeader", cnn)

                '创建填充 DataSet.
                Dim ds As New DataSet()
                cmd1.Fill(ds, "MenuHeader")
                'SqlHelper.ExcuteReadApdater("select * from authors", CommandType.Text, Nothing)
                ' 为Titles表创建 DataAdapter
                Dim cmd2 As New SqlDataAdapter("select * from c_MenuLeft", cnn)
                cmd2.Fill(ds, "MenuLeft")

                ' 创建 Authors 表和 Titles 表之间的关系.
                ds.Relations.Add("myrelation", ds.Tables("MenuHeader").Columns("id"), ds.Tables("MenuLeft").Columns("pid"))

                ' 绑定Authors到父Repeater
                parentRepeater.DataSource = ds.Tables("MenuHeader")
                Page.DataBind()

                cnn.Close()
                cnn.Dispose()
            End Sub
           
        End Class
    End Namespace

  • 相关阅读:
    ONVIFclient搜索设备获取rtsp解决开发笔记(精华文章)
    openldap---ldapsearch使用
    简单工厂模式
    编译和运行时,库在何处
    Linux 双网卡绑定技术
    统计某个字符个数,小数运算,小数加减乘除
    2cifang.com_2次方学习
    c/c++ extern “C”
    环境变量0831
    股票技巧
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175956.html
Copyright © 2011-2022 走看看