将dropdownlist存储到arraylist [英] store dropdownlist into arraylist

查看:180
本文介绍了将dropdownlist存储到arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将下拉列表项存储到arraylist中?

how can i store a dropdownlist item into arraylist?

推荐答案



一次检查一次

Hi,

check this once

        List<string> str = new List<string>();
        foreach (ListItem sd in ddllist.Items)
        {
            str.Add(sd.Value);
        }
</string></string>



所有最好的



All the Best


首先,如果可以避免使用数组列表,请不要使用-它们不是安全的类型,因此它们比应有的工作量更大,可读性更差.使用类型安全列表< T>反而.这样,您不必在使用数组元素之前就对其进行转换.

之后,这非常简单:
声明您的列表< T>具有适当类型的文件(无论您使用了什么加载了DropDownList的文件)
使用List.AddRange方法填充它,将其交给DropDownList.Items集合或所需的子集.
Firstly, don''t use an arraylist if you can avoid it - they aren''t type safe so they are more work and less readable than they should be. Use a typesafe List<T> instead. That way you don''t have to cast the array elements before you use them.

After that, it''s pretty simple:
Declare your List<T> with the appropriate type (whatever you have loaded the DropDownList with)
Fill it using the the List.AddRange method, handing it the DropDownList.Items collection or the subset you require.


//十进制2 ArryList可以保存项目的文本和值
ArrayList alText = new ArrayList();
ArrayList alValue = new ArrayList();
//复制第一个Arry列表中的文本"字段
foreach(objDDL.Items中的ListItem li)
{
alTextt.Add(li.Text);
}

//根据第一个ArrayList的值复制第二个数组列表中的value字段
foreach(alText中的对象项)
{
字符串val = objDDL.Items.FindByText(item.ToString()).Value;
alValue.Add(val);
}
// Decalre 2 ArryList to Hold the Text and Value of Items
ArrayList alText= new ArrayList();
ArrayList alValue = new ArrayList();
//Copy the Text field in the First Arry List
foreach (ListItem li in objDDL.Items)
{
alTextt.Add(li.Text);
}

//Copy the value field in the Second Array List based on First ArrayList value
foreach (object item in alText)
{
string val = objDDL.Items.FindByText(item.ToString()).Value;
alValue.Add(val);
}


这篇关于将dropdownlist存储到arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆