Use data. What is the correct way to do this?

S

shapper

Hello,

I have 10 labels in different parts of a page, each one displaying a
value.

I have a class that uses Linq to retrieve all those values from a
database and places them in its properties.

I don't want to create an instance of this class on each control init
event because I will be accessing the database 10 times.

What is the more correct way to call the data function once and fill
all labels?

Should I use a custom data source. How can I do that?

Thanks,

Miguel
 
M

Mark Rae [MVP]

I have 10 labels in different parts of a page, each one displaying a
value.

I have a class that uses Linq to retrieve all those values from a
database and places them in its properties.

I don't want to create an instance of this class on each control init
event because I will be accessing the database 10 times.

What is the more correct way to call the data function once and fill
all labels?

You say you have a class which retrieves all the values...

So just instantiate the class and then populate the labels e.g.

MyClass myClass = new MyClass();
MyLabel1.Text = myClass.Value1.ToString();
MyLabel2.Text = myClass.Value2.ToString();

etc.
Should I use a custom data source. How can I do that?

Why do you need one...?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top