更新时间:2022-06-03 03:21:03
这是您应该能够做到的.
(我创建了示例,假设您需要在GridView
中显示一些选定的Person
对象).您只需要根据需要更改以下代码:
Here is how you should be able to do it.
(I created the example assuming you need to show some selectedPerson
objects in theGridView
). 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();
}