Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey,

I'm creating a user control and was wondering about something. How would I be able to set the user control to have a datasource property like a listview or repeater.

Right now I have a property that I need populated with a collection that already exists as an object data source, I want to use that object data source again and set it in the user control instead of recalling the select method a second time. How would I go about doing so?

(Figure if I could just set a datasource of the collection in the user control like a listview then I would be set but if there is another way I'm open to suggestions. The user control's datasource property should only set another property inside the user control to the collection of the datasource)(Also if this doesn't make any sence ask me to re-explain sorry)
Posted

1 solution

Well, you have a DataSource property in your user control, in the set part of it you bind the value to the internal gridview or datalist you have in your user control, this should be straight forward, you don't recall the query again in within your user control.

User Control code behind
C#
public object DataSource
{
  set
  { 
    this.grdBills.DataSource =value;
  }
}


Of course this is an example.
 
Share this answer
 
Comments
MJ_ 2-Oct-12 15:25pm    
Yeah after thinking about it I figured to just do that. Was just looking at it sideways I guess :/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900