Hi,
i've try to bind WebGrid to my ObservableCollection. I set the DataSource property and later I call DataBind(). Furthermore I define a BoundField and add it to the WebGrid Columns.<ObservableCollection<myClass> myOberservableCollection;<this.WebGrid.DataSource= myOberservableCollection;<BoundFiled bf = new BoundField(); <bf.HeaderText = "Key";<bf.DataField="Key";<this.WebGrid.Columns.Add(bf);<this.WebGrid.DataBind();
In my class which represent the items in my ObservableCollection I implement INotifyPropertyChanged Interface and the PropertyChangedEventHandler.In all properties of this class I raise this event.<public class myClass : INotifyPropertyChanged
<public event PropertyChangedEventHandler PropertyChanged;<public void myPropertyChanged(string propertyname)< { If (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyname));<public int Key< { get { return _key; } set { _key = value; myPropertyChanged("Key"); }
But the properties are never been raised! I guess something is missing!?With similar behavoir on my WPF or Silverlight project it works fine with Infragistics Grid.
thx in advance
frank
Hello All,
Indeed, ObservableCollections were introduced in .NET primarily having in mind two-way connected databinding for WPF and Silverlight, where a change in the UI immediately means a change in the data model and vice verse (two-way databinding).
However, ASP.NET is a disconnected model, where a change on the client does not get popagated to the server right away - a postback / callback is needed. Then, the collection does not really have any state, so it needs to be reinstatiated first (from ViewState, Session or directly from data-store) and just then we can have the INotifyPropertyChanged logic kicks in.
In general, we are not 100% sure that ObservableCollection was designed to play with ASP.NET. For two-way databinding, I believe that declarative datasources with CRUD operations enabled is the way to go. Am I missing something? Is there an example where ObservableCollection and ASP.NET play well together?
hey frank I have also the same problem as you