LoadTemplate And ItemCreated Event

R

rioka

I'm going to display data with a repeater control, and each row can have
a different layout depending on the value of a column: for example, if
column A contains value "1" I want to display Column B; but if column A
contains value "2", I'm going to display column C and D. (real situation
is a bit more complicated, of course).


I've been searching around in the past few days trying to get experiences
from others having similar problems, but didn't find an easy and clean
solution.

As a final test, I simply try the following:

1. Create different controls for the different layouts
2. Load the appropriate template for each row in ItemCreated event
handler, using something like (rp is the repeater control)



Dim row As DataRowView = CType(e.Item.DataItem, DataRowView)

Select Case CType(row.Item("Group"), String)
Case "01"
rp.ItemTemplate = LoadTemplate("row05.ascx")
Case "02"
rp.ItemTemplate = LoadTemplate("row03.ascx")
...
Case Else
rp.ItemTemplate = LoadTemplate("row06.ascx")
End Select


The above code seems to work without problems, but I suppose there is
something wrong, since no one has ever mentioned such a trivial solution.

So the question is: which is the drawback of this solution? What's wrong?

TIA
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top