ListView Item数据绑定可能吗? [英] ListView Item databinding possible?

查看:78
本文介绍了ListView Item数据绑定可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题我可能是错的,但是可以绑定一个自定义类,比如说一个Persons类到listview项吗?
例如,假设我们获得了此类:

I may be wrong with this question, but is it possible to bind a custom class, lets say a Persons class to listview items?
For instance, lets assume we got this class:

Public Class Person
  Public Property Name As String
  Public Property Age As Integer
  Public Property Sex As String
End Class



是否可以将它们绑定到listview控件,以便它在列中显示每个值,而无论我更改一个人的值,它将在listview控件上自动更新?



Is it possible to bind them to a listview control so it display each value in a column, and whatever i change a person''s value it will automatically update on the listview control?

推荐答案

这可能会有所帮助.
绑定ListView的数据 [ http://www.visualwebgui.com/Developers/KB/tabid/654/article/w_ListView_CodeSample_DataBind_ListView_to_a_generic_List_Type/Default.aspx [ ^ ],这将非常有帮助


谢谢,
Imdadhusen
This may helpful.
Data binding a ListView[^]


Another solution at
http://www.visualwebgui.com/Developers/KB/tabid/654/article/w_ListView_CodeSample_DataBind_ListView_to_a_generic_List_Type/Default.aspx[^], this will be really helpful


Thanks,
Imdadhusen



这是简单的解决方案.

1)上人课
Hi
Here is simple solution.

1) Have the person class
public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    public string Sex { get; set; }

}



2)有一个静态的人收集类



2) Have a static person collection class

public static class PersonCollection
{
    private static IList<Person> persons = new List<Person>();
    public static void Add(Person person)
    {
        persons.Add(person);
    }
    public static IList<Person> GetAll()
    {
        return persons;
    }
}



3)将对象数据源添加到aspx页面.单击配置数据源".选择PersonCollection对象作为源,然后单击下一步.在选择选项卡中,选择方法"GetAll".完成配置.

4)在您的aspx页面上添加一个列表视图.设置数据源.单击配置列表视图(无更改),然后单击确定.

5)在页面加载事件中添加示例数据...



3) Add a object data source to your aspx page.Click Configure datasource. The choose PersonCollection object as source and click next. In the select tab choose the method ''GetAll''. Finish the configurations.

4) Add a list view to your aspx page. Set the data source. Click configure list view (nothing to change) and then click ok.

5)In the page load event add sample data...

Person person1 = new Person();
person1.Name = "Albin";
person1.Age = 10;
person1.Sex = "Male";
Person person2 = new Person();
person2.Name = "Augustina";
person2.Age = 5;
person2.Sex = "Female";

PersonCollection.Add(person1);
PersonCollection.Add(person2);


就这样.这些新人物对象将在列表视图中列出


Thats all. These new person objects will list in the list view


这篇关于ListView Item数据绑定可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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