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''!");

posted @   大树2  阅读(431)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示