将如何选择列表框项目 [英] How to listbox items will be selected
问题描述
大家好,
我有小查询,这里我试图根据字符串值选择列表框项目。
这里我绑定列表框,我有字符串ss =Agrinational Insurance Company Inc; American Agri-Business Insurance Company; American Agricultural Insurance Company
我需要选择的字符串项,Listbox中可用的项目当用户点击按钮时,项目将被选中。
任何人都可以请你分享任何解决方案。
我尝试了什么:
我尝试了谷歌的一些解决方案
Hi All,
I have small query,here i am trying to selected listbox items based on String values.
here i bind the Listbox,and i have string ss="Agrinational Insurance Company Inc;American Agri-Business Insurance Company;American Agricultural Insurance Company"
the string items i need to be selected,that items available in Listbox.When user click the button the items will be selected.
any body can u please share the any solution to me.
What I have tried:
I tried to some solutions from google
推荐答案
试试这样
try like this
protected void Page_Load(object sender, EventArgs e)
{
List<string> lst = new List<string>();
lst.Add("one");
lst.Add("Agrinational Insurance Company Inc");
lst.Add("two");
lst.Add("American Agri-Business Insurance Company");
lst.Add("three");
lst.Add("American Agricultural Insurance Company");
lst.Add("four");
ListBox1.SelectionMode = ListSelectionMode.Multiple;
ListBox1.DataSource = lst;
ListBox1.DataBind();
}
protected void btn_Click(object sender, EventArgs e)
{
string ss = "Agrinational Insurance Company Inc;American Agri-Business Insurance Company;American Agricultural Insurance Company";
string[] items = ss.Split(';');
foreach (ListItem item in ListBox1.Items)
{
if (items.Contains(item.Text))
item.Selected = true;
}
}
这篇关于将如何选择列表框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!