zoukankan      html  css  js  c++  java
  • 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''!");

  • 相关阅读:
    [No0000C9]神秘的掐指一算是什么?教教你也会
    [No0000C8]英特尔快速存储IRST要不要装
    [No0000C7]windows 10桌面切换快捷键,win10
    [No0000C6]Visual Studio 2017 函数头显示引用个数
    [No0000C4]TortoiseSVN配置外部对比工具
    [No0000C5]VS2010删除空行
    [No0000C3]StarUML2 全平台破解方法
    [No0000C2]WPF 数据绑定的调试
    [No0000C1]Excel 删除空白行和空白列VBA代码
    [No0000C0]百度网盘真实地址解析(不用下载百度网盘)20170301
  • 原文地址:https://www.cnblogs.com/csj007523/p/1160584.html
Copyright © 2011-2022 走看看