vs2005/.net2.0 控件实例之 下拉列表《DropDownList》
2006-05-29 00:12
417 查看
演示的主要有三个:
1,数据源是使用数组列表的数据,而且当选择改变时候,也会激发一个事件!
2,两级联动
3,动态添加下拉列表的项
其实在之前我也做过一个VB的实例,那个是用VS2003做的,如果你要看具体怎么从数据库拿出数据来填充的话请参考那个,地址是http://thcjp.cnblogs.com/archive/2006/03/03/342389.html
<!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>
DropDownList 控件演示一:<br />
<br />
数据源是使用数组列表的数据,而且当选择改变时候,也会激发一个事件!<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<br />
DropDownList 控件演示二:两级联动<br />
<br />
这个我们使用的是SQLSERVER数据库中自带的pubs库的authors表,实现的效果就是两个下拉列表是相关联的(这里使用了数据控件的 SqlDataSource控件,该控件将在后面的数据控件中再详细说明和演示);<br />
请选择城市 :<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="city" DataValueField="au_id">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="au_lname" DataValueField="au_lname">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
SelectCommand="SELECT [au_lname], [au_id] FROM [authors] WHERE ([au_id] = @au_id)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="au_id" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
SelectCommand="SELECT [au_id], [city] FROM [authors]"></asp:SqlDataSource>
<br />
DropDownList 控件演示三:动态添加下拉列表的项<br />
<br />
<asp:DropDownList ID="DropDownList4" runat="server">
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="在前面文本框里填上你要添加的文本,然后按我一下,再看下前面下拉列表里的值"
Width="519px" /><br />
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//因为要使用ArrayList,所以得引入Collections命名空间,VB就不用了,具体我还不知道为什么
using System.Collections;
public partial class _Default : System.Web.UI.Page
1,数据源是使用数组列表的数据,而且当选择改变时候,也会激发一个事件!
2,两级联动
3,动态添加下拉列表的项
其实在之前我也做过一个VB的实例,那个是用VS2003做的,如果你要看具体怎么从数据库拿出数据来填充的话请参考那个,地址是http://thcjp.cnblogs.com/archive/2006/03/03/342389.html
<!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>
DropDownList 控件演示一:<br />
<br />
数据源是使用数组列表的数据,而且当选择改变时候,也会激发一个事件!<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<br />
DropDownList 控件演示二:两级联动<br />
<br />
这个我们使用的是SQLSERVER数据库中自带的pubs库的authors表,实现的效果就是两个下拉列表是相关联的(这里使用了数据控件的 SqlDataSource控件,该控件将在后面的数据控件中再详细说明和演示);<br />
请选择城市 :<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="city" DataValueField="au_id">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="au_lname" DataValueField="au_lname">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
SelectCommand="SELECT [au_lname], [au_id] FROM [authors] WHERE ([au_id] = @au_id)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="au_id" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
SelectCommand="SELECT [au_id], [city] FROM [authors]"></asp:SqlDataSource>
<br />
DropDownList 控件演示三:动态添加下拉列表的项<br />
<br />
<asp:DropDownList ID="DropDownList4" runat="server">
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="在前面文本框里填上你要添加的文本,然后按我一下,再看下前面下拉列表里的值"
Width="519px" /><br />
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//因为要使用ArrayList,所以得引入Collections命名空间,VB就不用了,具体我还不知道为什么
using System.Collections;
public partial class _Default : System.Web.UI.Page
相关文章推荐
- vs2005/.net2.0 控件实例之 下拉列表《DropDownList》
- vs2005/.net2.0 控件实例之 单选列表和复选列表
- vs2005/.net2.0 控件实例之 单选列表和复选列表
- vs2005/.net2.0 控件实例之 按纽《Button》
- vs2005/.net2.0 控件实例之 单选按纽和复选框 <RadioButton><CheckBox>
- vs2005/.net2.0 控件实例之 单选按纽和复选框 <RadioButton><CheckBox>
- 实例4-5 实现联动打的下拉列表DropDownList控件
- vs2005/.net2.0 控件实例之 按纽《Button》
- [原创]Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)
- Visual Studio 2005入门 之 下拉列表(DropDownList) [视频]
- DropdownList下拉列表控件的使用
- 设定下拉列表控件DropDownList,复选按钮CheckBox,RadioButton默认值总结测试
- vs2005/.NET2.0 控件演示之 隐藏字段《FiddenField》
- [转载][教程]vs2005/.NET2.0 控件演示之 文件上传 《FileUpload》 (二)
- vs2005/.NET2.0 控件演示之 超级链接 《HyperLink》
- ASP.NET自定义Web服务器控件-DropDownList/Select下拉列表控件
- 设定下拉列表控件DropDownList,复选按钮CheckBox,RadioButton默认值总结测试
- DataSet&DataTable如何绑定下拉列表控件获取不重复的值,如何添加一列自定义文字,并在下拉列表控件中显示自定义文字[winform学习实例]
- vs2005/.NET2.0 控件演示之 超级链接 《HyperLink》
- vs2005/.NET2.0 控件演示之 隐藏字段《FiddenField》