Best way to implement custom control: Repeater vs. Anything Else

G

Guest

I am struggling with implementing somewhat complicated UI web-control. I
explored Repeater, but I am not sure if it's the best way to go. I am leaning
towards writing my own custom control and creating elements on the fly
dynamically.
I have a control that needs to display 3 columns and n number of rows
depending on number of records. Sounds simple. But each Row has a control
with its own data source binding and value must be selected based on data.
Each row can be removed by the user or new row added. So far Repeater can do
all that, and I developed a prototype that does it.
But The problem is that I need adjust colspan=x for different. If there's no
previous data, I need to hide 1 column which has delete button and do colspan
= 2 on the last column. So user has to create a new record. I can't find an
easy way to do it, rather then writing custom code on ItemDataBound event or
ItemCreated and adding HTML text programmatically. But what's the point
having Repeater control? I might as well write my own implementation.
 
L

Lars Netzel

I have basically done what you want to do in a datagrid..

In more complex Designsituations just use ONE templateColumn and then add
yoru own basic HTML code in there.. you can also add another DataGrid within
a DataGrid Cell so you can do whatever you want really... Jsut add and
remove those datagrids or other ServerControls in EditCommand and
UpdateCommand events of the datagrid... You really don't need to create you
own control, the DataGrid in ASP.NET is extremely powerful with some
customizing.

Best Regards
/Lars
 
G

Guest

My delima is really amount of code/effort I have invest in this control. It
seems to me that to customize DataGrid or Repeater, I have to write the same
amount of code as I would if I developed my own control. See, data comes
from XML stream, so I already have code that parses this XML, so all I have
to do now is to place a few Controls.Add to XML parsing logic.
With DataGrid I still have to have XML parsing logic to convert it to a
DataSet or some collection of objects so it can databinded to .NET control.
And then write extra code in ItemDataBound event. Is it worth the effort?
 
J

Joe Fallon

I jst finished building a page just like the one you describe!
I used a reapter and then nested a 2nd repeater inside the first one.
My biggest challenge was I need to do some work in ItemDataBound of the
nested repeater and it was not available in the code behind.

A little Google finally showed that all you do is add something like this
the <asp:repeater> tag:

<asp:repeater id=.... OnItemDataBound="nestedRptr_ItemDataBound" ...>

Then just add a Protected method named nestedRptr_ItemDataBound (using the
same signture as a normal repeater and minus any Handles statement).

Then I was able to cast the sender to a Repeater and use e as a DataItem.

I seriously considered calculating the HTML on my own and skip the whole
exercise. And I would have done so had I not been able to figure out this
trick.

Good luck.
 

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,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top