DropDownList操作;ListBox操作;动态创建控件;Response.Write("欢迎学习ASP.NET''!");


1   DropDownList操作;
2   ListBox操作;
3   动态创建控件;
4   Response.Write("欢迎学习ASP.NET''!");

=====================
1   DropDownList操作;(向右选择,向上移,向下移选项;)
if(DropDown1.Items.Count > 1)
   {
    ListItem Item = DropDown1.SelectedItem;
    DropDown1.Items.Remove(Item);
    String val = DropDown1.SelectedItem.Value ;
    String text = DropDown1.SelectedItem.Text;
    Label1.Text = val + text;
   }
   else
   {
    DropDown1.Items.Clear();
    Label1.Text = "";
   }

2   ListBox操作;(向右选择,向上移,向下移选项;)

private void Movebtn_Click(object sender, System.EventArgs e)
  {  
   int Count = ListBox1.Items.Count;
   int Index = 0;
   for(int i=0;i<Count-1;i++)
   {
    ListItem Item = ListBox1.Items[Index];
    if(ListBox1.Items[Index].Selected == true)
    {
     ListBox1.Items.Remove(Item);
     ListBox2.Items.Add(Item);
     Index--;
    }
    Index++;
   }
  }

  private void Upbtn_Click(object sender, System.EventArgs e)
  {
   //若不是第一行则上移
   if( ListBox1.SelectedIndex > 0 )
   {
    string name = ListBox1.SelectedItem.Text;
    string ID = ListBox1.SelectedItem.Value;
    int index = ListBox1.SelectedIndex;
    ListBox1.SelectedItem.Text = ListBox1.Items[index-1].Text;
    ListBox1.SelectedItem.Value = ListBox1.Items[index-1].Value;
    ListBox1.Items[index-1].Text = name;
    ListBox1.Items[index-1].Value = ID;
    ListBox1.SelectedIndex --;
   }
  }

  private void Downbtn_Click(object sender, System.EventArgs e)
  {
   //若不是最后一行则下移
   if( ListBox1.SelectedIndex >= 0 && ListBox1.SelectedIndex < ListBox1.Items.Count-1 )
   {
    string name = ListBox1.SelectedItem.Text;
    string ID = ListBox1.SelectedItem.Value;
    int index = ListBox1.SelectedIndex;
    ListBox1.SelectedItem.Text = ListBox1.Items[index+1].Text;
    ListBox1.SelectedItem.Value = ListBox1.Items[index+1].Value;
    ListBox1.Items[index+1].Text = name;
    ListBox1.Items[index+1].Value = ID;
    ListBox1.SelectedIndex ++;
   }
  }

3   动态创建控件;
private void Addbtn_Click(object sender, System.EventArgs e)
  {   
   DropDownList DropDown = new DropDownList();
   PlaceHolder1.Controls.Clear();
   PlaceHolder1.Controls.Add(DropDown);
   DropDown.ID="ControlID";
   DropDown.Width=200;
   DropDown.Items.Add(new ListItem("北京","0"));
   DropDown.Items.Add(new ListItem("上海","1"));
   DropDown.Items.Add(new ListItem("河北","2"));
   ViewState["AddControl"] = true;
  }


4   Response.Write("欢迎学习ASP.NET''!");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值