当前位置: 网站首页>网站建设>微信公众号开发

【网站优化】喀什企业网站设计 - 喀什高端网站定制 - 喀什品牌网站搭建 - 上往建站【简单基础中小型网站】

发表日期: 2022-09-01 14:28:59 浏览次数:64

上往建站提供网站建设网站推广网店设计网站建设企业网站网站制作网页设计网站建设企业网站制作网页制作   高端定制网站建设H5页面设计开发微网站微信运营移动端设计开发手机端网站小程序,致力于苏州企业网站建设与公司网站制作,全国用户超10万,10余年的网站开发和建站经验,主营:网站建设网络推广微信公众号代运营、商城小程序开发定制网店设计等业务,专业团队服务,效果好。。

服务热线:400-111-6878 手机微信同号:18118153152(各城市商务人员可上门服务)

喀什企业网站设计 - 喀什高端网站定制 - 喀什品牌网站搭建 - 上往建站

网站建设.png

ASP.NET Web Forms - Hashtable 对象


Hashtable 对象包含用键/值对表示的项目。


Examples

尝试一下 - 实例

Hashtable RadiobuttonList 1

Hashtable RadiobuttonList 2

Hashtable DropDownList


创建 Hashtable

Hashtable 对象包含用键/值对表示的项目。键被用作索引,通过搜索键,可以实现对值的快速搜索。

通过 Add() 方法向 Hashtable 添加项目。

下面的代码创建了一个名为 mycountries 的 Hashtable 对象,并添加了四个元素:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
end if
end sub
</script>



数据绑定

Hashtable 对象可为下列的控件自动生成文本和值:

  • asp:RadioButtonList

  • asp:CheckBoxList

  • asp:DropDownList

  • asp:Listbox

为了绑定数据到 RadioButtonList 控件,首先要在 .aspx 页面中创建一个 RadioButtonList 控件(不带任何 asp:ListItem 元素):

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

然后添加创建列表的脚本,并且绑定列表中的值到 RadioButtonList 控件:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

然后我们添加一个子例程,当用户点击 RadioButtonList 控件中的某个项目时,该子例程会被执行。当某个单选按钮被点击时,label 中会出现一行文本:

实例

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub

sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

演示实例 »

注释:您无法选择添加到 Hashtable 的项目的排序方式。如需对项目进行字母排序或者数字排序,请使用 SortedList 对象。


ASP.NET Web Forms - SortedList 对象

SortedList 对象结合了 ArrayList 对象和 Hashtable 对象的特性。


Examples

尝试一下 - 实例

SortedList RadiobuttonList 1


SortedList RadiobuttonList 2


SortedList DropDownList


SortedList 对象

SortedList 对象包含用键/值对表示的项目。SortedList 对象按照字母顺序或者数字顺序自动地对项目进行排序。


通过 Add() 方法向 SortedList 添加项目。通过 TrimToSize() 方法把 SortedList 调整为最终尺寸。


下面的代码创建了一个名为 mycountries 的 SortedList 对象,并添加了四个元素:


<script runat="server">

sub Page_Load

if Not Page.IsPostBack then

dim mycountries=New SortedList

mycountries.Add("N","Norway")

mycountries.Add("S","Sweden")

mycountries.Add("F","France")

mycountries.Add("I","Italy")

end if

end sub

</script>


数据绑定

SortedList 对象可为下列的控件自动生成文本和值:


asp:RadioButtonList

asp:CheckBoxList

asp:DropDownList

asp:Listbox

为了绑定数据到 RadioButtonList 控件,首先要在 .aspx 页面中创建一个 RadioButtonList 控件(不带任何 asp:ListItem 元素):


<html>

<body>


<form runat="server">

<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />

</form>


</body>

</html>

然后添加创建列表的脚本,并且绑定列表中的值到 RadioButtonList 控件:


<script runat="server">

sub Page_Load

if Not Page.IsPostBack then

dim mycountries=New SortedList

mycountries.Add("N","Norway")

mycountries.Add("S","Sweden")

mycountries.Add("F","France")

mycountries.Add("I","Italy")

rb.DataSource=mycountries

rb.DataValueField="Key"

rb.DataTextField="Value"

rb.DataBind()

end if

end sub

</script>


<html>

<body>


<form runat="server">

<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />

</form>


</body>

</html>

然后我们添加一个子例程,当用户点击 RadioButtonList 控件中的某个项目时,该子例程会被执行。当某个单选按钮被点击时,label 中会出现一行文本:


实例

<script runat="server">

sub Page_Load

if Not Page.IsPostBack then

dim mycountries=New SortedList

mycountries.Add("N","Norway")

mycountries.Add("S","Sweden")

mycountries.Add("F","France")

mycountries.Add("I","Italy")

rb.DataSource=mycountries

rb.DataValueField="Key"

rb.DataTextField="Value"

rb.DataBind()

end if

end sub


sub displayMessage(s as Object,e As EventArgs)

lbl1.text="Your favorite country is: " & rb.SelectedItem.Text

end sub

</script>


<html>

<body>


<form runat="server">

<asp:RadioButtonList id="rb" runat="server"

AutoPostBack="True" onSelectedIndexChanged="displayMessage" />

<p><asp:label id="lbl1" runat="server" /></p>

</form>


</body>

</html>


演示实例 »


喀什企业网站设计 - 喀什高端网站定制 - 喀什品牌网站搭建 - 上往建站


上往建站提供微信小程序+公众号商城+企业网站建设一站式微信网站商城营销系统,微信小程序是一种依附于微信体内即点即用,无需下载安装即可使用的轻应用,它开启了移动端“触手可及”的梦想,致力于苏州企业网站建设与公司网站制作,全国用户超10万,10余年的网站开发和建站经验,主营:网站建设微信公众号代运营商城小程序开发定制网店设计等业务,专业团队服务,效果好。

服务热线:400-111-6878 手机微信同号:18118153152(各城市商务人员可上门服务)


400-111-6878
服务热线
顶部

备案号: 苏ICP备2021016738号-6

CopyRight © 2021 上往建站 All Right Reserved 未经许可不得复制转载

24小时服务热线:400-111-6878   E-MAIL:1120768800@qq.com   QQ:1120768800

  网址: https://www.768800.club  网站建设上往建站

关键词: 网站建设| 域名邮箱| 服务器空间| 网站推广| 上往建站| 网站制作| 网站设计| 域名注册| 网络营销| 网站维护|

企业邮箱| 虚拟主机| 网络建站| 网站服务| 网页设计| 网店美工设计| 网站定制| 企业建站| 网站设计制作| 网页制作公司|

400电话办理| 书生商友软件|

预约专家

欢迎您免费咨询,请填写以下信息,我们收到后会尽快与您联系

  

全国服务热线:400-111-6878