Asp.Net Web 常用控件

本文介绍了ASP.NET Web开发中常用的文本控件,包括ListBox列表框控件和DropDownList下拉列表控件的使用,详细说明了控件的行为设置和代码实现。同时,也探讨了选择类型控件,如RadioButton单选按钮和CheckBox多选控件的配置,包括GroupName设置和事件触发的代码编写。
摘要由CSDN通过智能技术生成

文本控件

1)ListBox列表框控件

cc56105be2ef9bdfb772f0adba55636b.png 

在设计页面设计好,拖2个ListBox。1个label(显示你所选择的日期), 4个button(全往右,全往左,几个往右,几个往左,总共4个功能)

注意调整ListBox控件行为True

 代码如下:

using System.Collections;

namespace WebApplication1
{
    //listbox列表控件
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)//是否回传
            {
                ArrayList arrrayl = new ArrayList();  //实例化数组集合
                arrrayl.Add("星期日");                 //向集合中添加数据
                arrrayl.Add("星期一");
                arrrayl.Add("星期二");
                arrrayl.Add("星期三");
                arrrayl.Add("星期四");
                arrrayl.Add("星期五");
                arrrayl.Add("星期六");
                ListBox1.DataSource = arrrayl; //数据来源绑定到Listbox控件中
                ListBox1.DataBind();//执行绑定操作
            }
                      
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //ListBox1每一项的数据传输到ListBox2
            int count = ListBox1.Items.Count;
            //用循环遍历
            for (int i = 0; i < count; i++)
            {
                //count的值就是ListBox1数据的个数,如上为7
                ListItem item = ListBox1.Items[0];
                ListBox1.Items.Remove(item); //把ListBox1的数据取出到ListBox2,并删除ListBox1的取出数据
                ListBox2.Items.Add(item);

            }
       
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            //ListBox2每一项的数据传输到ListBox2
            int count = ListBox2.Items.Count;
            //用循环遍历
            for (int i = 0; i < count; i+
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值