Connecting Tech Pros Worldwide Forums | Help | Site Map

Writing bound controls

balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#1: Nov 20 '08
I've got a composite custom control that I've bound to a data object. All works find - but when I modify the data in the data object that is bound - how do I get my custom control to re-read from the master data source?

I know I run DataBind() to get it to rebuild from the data source, but the data held inside the control is still the old data unless I set the data source again:

i.e.
MyControl.DataSource = MasterData
MyControl.DataBind()

in an ideal world I'd be able to modify MasterData and then just call MyControl.DataBind()

Given that we can't set a property ByRef - how do I get my control to read its data from the master in a similar fashion?

Pseudo code is fine - I'm sure I'm just missing a concept here...

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Nov 20 '08

re: Writing bound controls


I think in this case you would need to re-set it unfortunatly.

What I have done in the past, when dealing with windows apps at least, is to be like:
Expand|Select|Wrap|Line Numbers
  1.  
  2. object o =mySomeThingWithADataSource.DataSource;
  3. //for me this is usually a DataTable or some form of a table so I do:
  4. int numrows = ( (DataTable)  mySomeThingWithADataSource.DataSource).Rows.Count;
  5.  
  6.  
And then I do my workings on THAT object, as i generally let the program lose reference to the original object that I supplied to the DataSource
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#3: Nov 20 '08

re: Writing bound controls


Quote:

Originally Posted by Plater

I think in this case you would need to re-set it unfortunatly.

What I have done in the past, when dealing with windows apps at least, is to be like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. object o =mySomeThingWithADataSource.DataSource;
  3. //for me this is usually a DataTable or some form of a table so I do:
  4. int numrows = ( (DataTable)  mySomeThingWithADataSource.DataSource).Rows.Count;
  5.  
  6.  
And then I do my workings on THAT object, as i generally let the program lose reference to the original object that I supplied to the DataSource

Yeah, I was afraid you were going to say that... maybe I'll plug some reflection into my control and see if I can grab a handle to the original and attach it somehow...

It would be nice if I could have it just bind to the master data source so I don't have to keep worrying about accessing the one contained in my control.

In Javascript you can supply an inline functions as parameters so that it'll do things like this... I'm curious if I can force a lambda expression in there in a similar fashion...
Reply