📄 databind.aspx
字号:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<script language="VB" runat="server">
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=ASPNET;User ID=sa;"
myConnection = New OleDbConnection(ConnStr)
if NOT (isPostBack)
bind
end if
End Sub
Sub Bind()
'DataSetCommand
SQL = "select * from Groups"
myCommand = New OleDbDataAdapter(SQL, myConnection)
'use Fill method of DataSetCommand to populate dataset
myCommand.Fill(ds, "Groups")
list1.DataSource=ds.Tables("Groups").DefaultView
list1.DataBind()
rb.DataSource=ds.Tables("Groups").DefaultView
rb.DataBind()
dl.DataSource=ds.Tables("Groups").DefaultView
dl.DataBind()
End Sub
Sub SubmitBtn_Click(sender As Object, e As EventArgs)
Dim s as string
s = s + "----Selected DropDownList : " + dl.SelectedItem.Text
Label1.Text = s
End Sub
</script>
<body>
<h3><font face="Verdana">Binding Controls </font></h3>
<form runat=server>
<asp:ListBox id="List1" DataTextField = "code_display" DataValueField = "code_value" runat="server"/>
<hr>
<ASP:radiobuttonList
repeatcolumns="4" repeatdirection="horizontal" repeatlayout="table"
id="rb" datatextfield="code_display" DataValueField="code_value" runat="server"/>
<hr>
<asp:DropDownList id="dl" DataTextField = "code_display" DataValueField = "code_value" runat="server"/>
<hr>
<asp:button Text="Submit" OnClick="SubmitBtn_Click" runat=server/>
<asp:Label id=Label1 font-name="Verdana" font-size="10pt" runat="server" />
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -