列表控件(DropDownList,ListBox和BulletedList).aspx
<%
...
@ Page Language="C#" AutoEventWireup="true" CodeFile="列表控件(DropDownList,ListBox和BulletedList).aspx.cs" Inherits="列表控件_DropDownList_ListBox和BulletedList_"
%>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
列表控件(DropDownList,ListBox和BulletedList)
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
<
asp:DropDownList
ID
="DropDownList1"
runat
="server"
OnSelectedIndexChanged
="DropDownList1_SelectedIndexChanged"
AutoPostBack
="True"
>
<
asp:ListItem
>
江苏
</
asp:ListItem
>
<
asp:ListItem
>
北京
</
asp:ListItem
>
<
asp:ListItem
>
上海
</
asp:ListItem
>
<
asp:ListItem
>
广州
</
asp:ListItem
>
<
asp:ListItem
>
湖南
</
asp:ListItem
>
</
asp:DropDownList
>
<
br
/>
<
br
/>
<
br
/>
<
asp:ListBox
ID
="ListBox1"
runat
="server"
OnSelectedIndexChanged
="ListBox1_SelectedIndexChanged"
AutoPostBack
="True"
>
<
asp:ListItem
>
音乐
</
asp:ListItem
>
<
asp:ListItem
>
游戏
</
asp:ListItem
>
<
asp:ListItem
>
电影
</
asp:ListItem
>
<
asp:ListItem
></
asp:ListItem
>
</
asp:ListBox
><
br
/>
<
br
/>
<
br
/>
<
asp:BulletedList
ID
="BulletedList1"
runat
="server"
DisplayMode
="linkButton"
OnClick
="BulletedList1_Click"
>
<
asp:ListItem
>
数学
</
asp:ListItem
>
<
asp:ListItem
>
美术
</
asp:ListItem
>
<
asp:ListItem
>
英语
</
asp:ListItem
>
<
asp:ListItem
>
计算机
</
asp:ListItem
>
</
asp:BulletedList
>
<
br
/>
<
br
/>
我现在主要想理解的就是各个空件里面怎样很好的调用各个列表控件里面的每一个属性。Text 或者Value属性倒是没有什么,只要能定位到每一个属性就好,下面我就做一个测试看下
<
br
/>
<
asp:TextBox
ID
="TextBox1"
runat
="server"
Style
="position: relative"
Width
="581px"
></
asp:TextBox
><
br
/>
根据上面的选择我们在这个里面显示数据
<
br
/>
<
br
/>
晕死开始右犯了个错误 郁闷啊,AutoPostBack没有设置点了半天没有反应 呵呵。 BS下自己。
<
br
/>
<
br
/>
还有就是这三个空件也都可以进行数据的绑定,和上一个例题里面几乎一样
<
br
/>
就试一个看下
<
br
/>
<
asp:BulletedList
ID
="BulletedList2"
DisplayMode
="linkButton"
runat
="server"
DataSourceID
="SqlDataSource1"
DataTextField
="BLname"
DataValueField
="BLid"
Style
="position: relative"
Width
="250px"
OnClick
="BulletedList2_Click"
>
</
asp:BulletedList
>
<
asp:SqlDataSource
ID
="SqlDataSource1"
runat
="server"
ConnectionString
="<%$ ConnectionStrings:DBCONNECTIONSTRING %>"
SelectCommand
="SELECT [BLname], [BLid] FROM [BulletedList]"
></
asp:SqlDataSource
>
</
div
>
</
form
>
</
body
>
</
html
>
列表控件(DropDownList,ListBox和BulletedList).aspx.cs
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
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;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
public
partial
class
列表控件_DropDownList_ListBox和BulletedList_ : System.Web.UI.Page
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
protected void Page_Load(object sender, EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.TextBox1.Text = this.DropDownList1.SelectedItem.Text;
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.TextBox1.Text = this.ListBox1.SelectedItem.Text;
}
protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.TextBox1.Text = this.BulletedList1.Items[e.Index].Text;
}
protected void BulletedList2_Click(object sender, BulletedListEventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.TextBox1.Text = this.BulletedList2.Items[e.Index].Text;
}
}