Link to home
Start Free TrialLog in
Avatar of handicomp
handicomp

asked on

Repeating a web user control - Please help!

Hopefully I can explain my problem clearly,

I have a fairly complex display (a scorecard) that is a web user control (containing many various type asp.net controls) on a page. It is populated by a custom data collection (an object I've named "TPD").  This works great to display one scorecard at a time. The problem is that I want to display multiple (a variable number) scorecards on a single page.

I've looked at repeater controls but my display (the scorecard) does not fit the conventional iterative controls (list control, datagrid etc) and I don't think that route would work for me anyway.

I have done similar in the past without using a web user control as follows:

- Loop through the data and each time through the loop append a string with standard html (no web user control, no asp.net controls) representing a scorecard.

- Assign the completed string to the text property of a literal control which renders it to the screen.



Another solution (that I find basically unworkable but might explain what I am trying to do!) is as follows:

- Put 50 (or some large number) instances of the web user control on the page and hidden.

- Then loop through the data and create x number of data objects (the "TPD's" I mentioned earlier)

- Populate and make visible as many of the web user controls as necessary.

This seems messy and inefficient to me! Am I missing something completely obvious here?

Any guidance would be appreciated.

Thanks in advanced!

Avatar of CJ_S
CJ_S
Flag of Netherlands image

Well - to answer your question, you will need to provide us with a little more input. Most important being how you currently populate your usercontrol with data.

The best way to accomplish the wanted behaviour would be to:

a) create the user control in such a way that the data is set and then databound.
b) add one user control to the page OR put it within a repeater.
c) retrieve one instance OR a collection of instances and bind these to your user control.

If your user control allows to bind itself to a datasource then your control behaves just like all the existing webcontrols.
if you know the number of scorecards you're creating, you can use that count to loop and dynamically add scorecard user controls to the page in a placeholder control...
You can start with this:
http://aspalliance.com/565_Dynamic_Loading_of_ASPNET_User_Controls

which adds one header control to a placeholder, but you can do the "placeholder.controls.add" part in a loop...you would also bind each scorecard before adding it to the placeholder
Avatar of handicomp
handicomp

ASKER

Thanks for the quick response!

I don't databind the control in a manner that I believe you are refering to. But maybe I should be! Let me try to explain.

I call the control from the page something like:

MyUserControl.initialize()

In the user control, in the initialize() sub, I create the data object (I call "TPD" (acronym for team player data)) then begin assesing data within the "TPD" to condition the display like:

if tpd.team(1).player(1).spectype = "G"c then
PanelT1P1Ghost.visible = true
end if

etc...

I don't do anything like "MyUserControl.databind()". Does it appear that my "MyUserControl.initialize()" sub acts the same as an "official" databind()? if so a can probably move my initialize into a databind. I think I need to start by databinding the control correctly. Then it sounds like i can progress as you've both outlined. Am i on the right track?

P.S. This is the first time I've actually used experts exchange. I was going to "Accept as Solution" but I think that it will "close my ticket". Regardless, I'll do the points thing as soon as i figure this site out!

Thanks again.



well, I was assuming that the scorecard somehow gets it's data from a database ...and it sounds like you're doing that in your TPD object.
so I'm assuming somehow TPD knows which scorecard data to get...somewhere you're passing in a userID or scorecardID or something right?
so even though I used the word "databind"...you don't have to truly do a "databind" perse if each scorecard/TPD is getting the data somehow.

I'm making these assumptions because I imagine that if you're going to show multiple scorecards, each scorecard is going to have different data in it right?

so what is it in each scorecard user control/TPD that gets the correct data?
that is what you would loop through to initialize/"databind" each scorecard and then add it to a placeholder...

so the pseudocode steps would be something like:

1. get the list (or dataset or datatable) of id's that will be passed to each scorecard
2. create a loop to loop through that list
3. "initialize"/"databind" a scorecard and pass it the id from the loop so that the scorecard loads the correct data
4. Add it to the placeholder
5. go to next "id" in the loop, repeat 3 -5 until the end of the list of "id's"

hope that makes sense!
ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Guys,

I'll try it out and get back.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Samtran:

>>each scorecard is going to have different data in it right? - This is correct.

>>so what is it in each scorecard user control/TPD that gets the correct data? -

- Currently on the page that calls the user control I set two variables for the user control before initializing it like:
----------------------------------------
'from the calling page:
MyUserControl.roundID = 4321          'a public shared variable in the user control
MyUserControl.pairingID = 1234         'a public shared variable in the user control
MyUserControl.Initialize()
---------------------------------------

then within the "initialize()" routine I create the TDP object using the roundID and the pairingID.

the TPD is a serializable class populated from the database contain mutiple arrays and values like

team(1)
      teamName
         Player(1)
              playername
              playerscores()
         Player(2)
              playername
              playerscores()
team(2)
      teamName
         Player(1)
              playername
              playerscores()
         Player(2)
              playername
              playerscores()

etc...

once the TPD is created I start populating the display.

I plan on looping through a given round, getting each pairingID then create each TPD/scorecard

BTW your psuedocode steps make a lot of sense and I'll try it.

CJ:

Thanks a lot for your suggestion. I'm a vb guy so I'm working through your code and it too looks like an good option.

Thanks to you both and I'll let you know how it goes.