首页  ·  知识 ·  云计算
两个list中的item之间添加与清除,顺序变动
:Holmes·Conan  http://dev.csdn.net/author/hanchi8008/85b5bc123d5d  综合  编辑:dezai  图片来源:网络
1.将datatable的值给List DataTable allColumns = (DataTable)Session["allColu

1.将datatable的值给List

 

         DataTable allColumns = (DataTable)Session["allColumns"];
                if(null != allColumns)
                {
                    foreach(DataColumn dc in allColumns.Columns)
                    {
                        ListColumnName.Items.Add(dc.ColumnName+"("+dc.DataType.Name+")");
                    }
                }
 

 2.两个list中的item之间添加与清除,顺序变动

//add
            bool flag=false;
            ListItem listItem=ListColumnName.SelectedItem;
            if(listItem!= null)
            {
                foreach (ListItem listItem1 in ListPrimaryKey.Items)
                {
                    if (listItem1.Text== listItem.Text)
                    {
                        flag=true;
                    }
                }
                if(flag== false)
                {
                    ListPrimaryKey.Items.Add(listItem);
                    ListColumnName.Items.Remove(listItem);   
                    ListPrimaryKey.SelectedIndex=-1;
                    ListColumnName.SelectedIndex=-1;
                }   
            }

//up
            int i=ListColumnName.SelectedIndex;
            if ( i >0)
            {
                ListItem listItem= new ListItem(ListColumnName.Items[i-1].Text,ListColumnName.Items[i-1].Value);
                ListColumnName.Items[i-1].Text=ListColumnName.Items[i].Text;
                ListColumnName.Items[i].Text=listItem.Text;
                ListColumnName.SelectedIndex=i-1;
                ListPrimaryKey.SelectedIndex=i-1;
            }
 

//remove
            ListItem listItem=ListPrimaryKey.SelectedItem;
            bool flag=false;
            if (listItem!= null)
            {
                foreach (ListItem listItem1 in ListColumnName.Items)
                {
                    if (listItem1.Text== listItem.Text)
                    {
                        flag=true;
                    }

                }
                if(flag== false)
                {
                    ListColumnName.Items.Add(listItem);
                    ListColumnName.SelectedIndex=-1;
                }
                ListPrimaryKey.Items.Remove(listItem);
                ListPrimaryKey.SelectedIndex=-1;
            }
//down
            int i=ListColumnName.SelectedIndex;
            if ( i >=0 && i            {
                ListItem listItem= new ListItem(ListColumnName.Items[i].Text,ListColumnName.Items[i].Value);
                ListColumnName.Items[i].Text=ListColumnName.Items[i+1].Text;
                ListColumnName.Items[i+1].Text=listItem.Text;
                ListColumnName.SelectedIndex=i+1;
                ListPrimaryKey.SelectedIndex=i+1;
            }

本文作者::Holmes·Conan 来源:http://dev.csdn.net/author/hanchi8008/85b5bc123d5d
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读