~
Lv 6
~ asked in 電腦與網際網路程式設計 · 1 decade ago

ASP.NET如何把dim的checkboxlist放到表單

<%@ Page Language="VB" %><%@ Import Namespace="System.Data" %><%@ Import NameSpace="System.Data.OleDb" %><html><body><form name="from1" runat="server"> <asp:checkboxlist runat="server" id="a" name="a"/></form></body></html><script Language="VB" runat="server">Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load             Dim a As New CheckBoxList        Dim i As Integer     Dim Conn As OleDbConnection Dim Cmd As OleDbCommand Dim Rd As OleDbDataReader Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0" Dim Database = "Data Source=" & Server.MapPath( "a2.mdb" ) Conn = New OleDbConnection( Provider & ";" & DataBase ) Conn.Open() Cmd = New OleDbCommand( "Select * from 檢驗類別主項", Conn ) dim ii as Integer ii=0 Rd = Cmd.ExecuteReader()While Rd.Read() a.Items.Add(New ListItem(Rd.Item(0),Rd.Item(0)))  End WhileConn.Close()        Me.Controls.Add(a)    \'←是這行出問題…請問如何把dim的checkboxlist放到表單中?End Sub  </script>

1 Answer

Rating
  • 1 decade ago
    Best Answer

    有兩種方式

    1.aspx已經有一個checkboxlist的控制項

    <body>

    <form name="from1" runat="server">

    <asp:checkboxlist runat="server" id="a" name="a"/>

    </form>

    Dim Conn As OleDbConnection

    Dim Cmd As OleDbCommand

    Dim Rd As OleDbDataReader

    Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0"

    Dim Database = "Data Source=" & Server.MapPath( "a2.mdb" )

    Conn = New OleDbConnection( Provider & ";" & DataBase )

    Conn.Open()

    Cmd = New OleDbCommand( "Select * from 檢驗類別主項", Conn )

    Rd = Cmd.ExecuteReader()

    While Rd.Read()

    a.Items.Add(New ListItem(Rd.Item(0),Rd.Item(0)))

    End While

    Conn.Close()

    2.動態產生的控制項

    <form name="from1" runat="server">

    <!-- 擺一個容器 -->

    <asp:Panel id="Panel1" runat="server" asp:Panel>

    </form>

    Dim a As New CheckBoxList

    Dim Conn As OleDbConnection

    Dim Cmd As OleDbCommand

    Dim Rd As OleDbDataReader

    Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0"

    Dim Database = "Data Source=" & Server.MapPath( "a2.mdb" )

    Conn = New OleDbConnection( Provider & ";" & DataBase )

    Conn.Open()

    Cmd = New OleDbCommand( "Select * from 檢驗類別主項", Conn )

    Rd = Cmd.ExecuteReader()

    While Rd.Read()

    a.Items.Add(New ListItem(Rd.Item(0),Rd.Item(0)))

    End While

    Conn.Close()

    Panel1.Controls.Add(a)

    Source(s): 自己
Still have questions? Get your answers by asking now.