列表框控件 [英] Listbox control

查看:70
本文介绍了列表框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我的问题是,如果我从列表框中选择多个项目,并基于该选择,则与这些项目相关的数据将显示在gridview中.

例如.我已根据选定的多个列名称为列表框分配了1个列名称(如名称),在gridview中显示数据(仅选择了相关数据).


Hi friends,

My question is, If I select multiple items from listbox and based on that selection, those items related data will be display in gridview.

Eg. I have assigned 1 column name like name to listbox, based on selected multiple columns names, display data (that selected related data only) in gridview.


Can any one clarify this for me or suggest how I can solve my problem?

推荐答案

这是您应该能够做到的.

(我创建了示例,假设您需要在GridView中显示一些选定的Person 对象).您只需要根据需要更改以下代码:

Here is how you should be able to do it.

(I created the example assuming you need to show some selected Person objects in the GridView). You just need to change the following code according to your need:

///<summary>
///Load selected Persons in the GridView
///</summary>
private void LoadPersons()
{
    //Get the selected indexes
    int[] indeces = ListBox1.GetSelectedIndices();

    foreach (int index in indeces)
    {
        ListItem item = ListBox1.Items[index];
        int Id = Convert.ToInt32(item.Value);
        //Load person by ID
        Person person = GetPersonById(Id);
        if (person != null)
        {
            persons.Add(person);
        }
    }
    //Bind GridView
    GridView1.DataSource = persons;
    GridView1.DataBind();
}


这篇关于列表框控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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