string a = "apple|orange|banana|grape|bbbb"; string[] b = a.Split('|'); ArrayList c = new ArrayList(); for(int i = 0;i<b.Length;i++) { c.Add(new ListItem(b[i],b[i])); } DropDownList1.DataSource=c; DropDownList1.DataBind();
数组可以直接作为数据源吧:string a = "apple|orange|banana|grape|bbbb"; string[] b = a.Split('|'); DropDownList1.DataSource = b; DropDownList1.DataBind();
string[] a=str.Split('|');
for(int i=0;i<a.Length;i++)
{
this.DropDownList1.Items.Add(a[i]);
}
string[] b = a.Split('|');
ArrayList c = new ArrayList();
for(int i = 0;i<b.Length;i++)
{
c.Add(new ListItem(b[i],b[i]));
}
DropDownList1.DataSource=c; DropDownList1.DataBind();
string[] b = a.Split('|');
DropDownList1.DataSource = b;
DropDownList1.DataBind();