ASP Web控件-----ListBox

  1. 样板 <asp:ListBox ID="ListBox1" runat="server" Height="20px" Width="73px">
                <asp:ListItem Selected="True" Value="1">第一项</asp:ListItem>
                <asp:ListItem Value="2">第二项</asp:ListItem>
                <asp:ListItem Value="3">第三项</asp:ListItem>
                <asp:ListItem Value="4">第四项</asp:ListItem>
         </asp:ListBox>
  2. 添加ListItem项
    1. 在页面上选编辑项----添加Item项 确定

    2. 在Listbox属性页面里 Item集合
    3. 编程方式
      if (!IsPostBack)
      {
           ListBox1.Items.Add("第一项");
           ListBox1.Items.Add("第二项");
           ListBox1.Items.Add("第san项");
           ListBox1.Items.Add(new ListItem("第四项""4"true));
      }

      Item.Add(string Item); Item.Add(ListItem Item);//可控制text value enabled属性

      protected void Button1_Click(object sender, EventArgs e)
      {
           this.Label1.Text = this.ListBox1.SelectedValue+ "---"+ListBox1.SelectedItem.Text;
      }//
      ListBox1.SelectedItem.Value 选中的value值  Item.Text显示的文本  ListBox1.SelectedIndex.ToString()从0开始,选中的为第几项
      



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值