<%@ Page Language="VB" AutoEventWireup="false" CodeFile="下拉列表数据绑定.aspx.vb" Inherits="下拉列表数据绑定" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head>
<script language="VB" runat="server"> '再页面装载的时候调用的方法:
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim values as ArrayList= new ArrayList()
values.Add ("北京")
values.Add ("深圳")
values.Add ("上海")
values.Add ("广州")
values.Add ("南宁")
values.Add ("重庆")
'设定DropDown1的数据源为values,即上面定义的信息DropDown1.DataSource = values '数据的绑定
DropDown1.DataBind()
End If
End Sub
'提交按钮响应的方法
Sub select02_Click(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = "你的选择是: " + DropDown1.SelectedItem.Text
End Sub
</script>
</head>
<body BGCOLOR="#CCCCFF">
<center> <h3><font face="Verdana">.NET->列表控件</font></h3> </center>
<center> <form id="Form1" runat=server>
<!--列出列表信息--> <asp:DropDownList id="DropDown1" runat="server" />
<asp:button ID="Button1" Text="提交" OnClick="select02_Click" runat=server/> <p>
<asp:Label id=Label1 font-name="Verdana" font-size="10pt" runat="server" /> </form> </center>
</body>
</html>
以上是我的代码 运行的时候 为什么下拉列表里面的内容为空 而没有设定的北京上海等地名
<head>
<script language="VB" runat="server"> '再页面装载的时候调用的方法:
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim values as ArrayList= new ArrayList()
values.Add ("北京")
values.Add ("深圳")
values.Add ("上海")
values.Add ("广州")
values.Add ("南宁")
values.Add ("重庆")
'设定DropDown1的数据源为values,即上面定义的信息DropDown1.DataSource = values '数据的绑定
DropDown1.DataBind()
End If
End Sub
'提交按钮响应的方法
Sub select02_Click(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = "你的选择是: " + DropDown1.SelectedItem.Text
End Sub
</script>
</head>
<body BGCOLOR="#CCCCFF">
<center> <h3><font face="Verdana">.NET->列表控件</font></h3> </center>
<center> <form id="Form1" runat=server>
<!--列出列表信息--> <asp:DropDownList id="DropDown1" runat="server" />
<asp:button ID="Button1" Text="提交" OnClick="select02_Click" runat=server/> <p>
<asp:Label id=Label1 font-name="Verdana" font-size="10pt" runat="server" /> </form> </center>
</body>
</html>
以上是我的代码 运行的时候 为什么下拉列表里面的内容为空 而没有设定的北京上海等地名
然后绑定这个 DataSet
另外,怎么用中文文件名?
dropdownlist1.DataTextField="values" '绑定字段的名字,我就不知道你那叫什么名字
DropDown1.DataBind()
End If
出来看看
Partial Class 下拉列表数据绑定
Inherits System.Web.UI.PageEnd Class还有请教下cpp2017(慕白兄) Page_Load在什么情况下是 不会执行的
this.Load+=new System.EventHandler(this.Page_Load)
把它们挂钩!去掉上面那一句后,asp.net默认事件和事件处理程序就自动挂钩!