How to bind Listview to Ilist
-
i have a small rec in which i have to bind the listview with the Ilist which is a generic collection.
cheers chandu
-
i have a small rec in which i have to bind the listview with the Ilist which is a generic collection.
cheers chandu
Data Binding Overview: Binding to Collections[^]
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
i have a small rec in which i have to bind the listview with the Ilist which is a generic collection.
cheers chandu
create on class like product and do the following things using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public class Product { private string _productName; public string ProductName { get { return this._productName; } set { this._productName = value; } } public Product() { } } -------------------- then create other calls public class ProductRepository { public static IList GetProducts(string criteria) { string key = "Products_" + criteria[0]; IList list = CacheRepository.GetObjects(key); if (list == null || list.Count == 0) { list = DataAccess.GetProducts(criteria); CacheRepository.SaveObject(key, list); } // return the list based on the criteria List productList = list as List; list = productList.FindAll(delegate(Product product) { return product.ProductName.ToLower().StartsWith(criteria.ToLower()); }); return list; } } ------------------------------- public class DataAccess { public static IList GetProducts(string criteria) { List list = new List(); // Fill the list with any data source while (reader.Read()) { Product product = new Product(); product.ProductName = reader["name1"] as String; list.Add(product); //which fill the list } } return list; } } ------------------------------ Then in the Page_Load or any method you can bind this way IList list = null; Listview listview = new Listview(); listview.DataSource = list; listview.DataBind();
-
create on class like product and do the following things using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public class Product { private string _productName; public string ProductName { get { return this._productName; } set { this._productName = value; } } public Product() { } } -------------------- then create other calls public class ProductRepository { public static IList GetProducts(string criteria) { string key = "Products_" + criteria[0]; IList list = CacheRepository.GetObjects(key); if (list == null || list.Count == 0) { list = DataAccess.GetProducts(criteria); CacheRepository.SaveObject(key, list); } // return the list based on the criteria List productList = list as List; list = productList.FindAll(delegate(Product product) { return product.ProductName.ToLower().StartsWith(criteria.ToLower()); }); return list; } } ------------------------------- public class DataAccess { public static IList GetProducts(string criteria) { List list = new List(); // Fill the list with any data source while (reader.Read()) { Product product = new Product(); product.ProductName = reader["name1"] as String; list.Add(product); //which fill the list } } return list; } } ------------------------------ Then in the Page_Load or any method you can bind this way IList list = null; Listview listview = new Listview(); listview.DataSource = list; listview.DataBind();
I am using Nhibernate. how to get data from database , assign the result set to the Ilist and bind that Ilist to the ListView in wpf. thanks for your reply... its helpful
cheers chandu
-
I am using Nhibernate. how to get data from database , assign the result set to the Ilist and bind that Ilist to the ListView in wpf. thanks for your reply... its helpful
cheers chandu
why you can not bind the data directly to the listview rather then putting it into IList is there any specific reason? let me know so I can help you better. ;) Will this may be helpful? http://www.theserverside.net/tt/articles/showarticle.tss?id=NHibernate[^]