Link to home
Start Free TrialLog in
Avatar of crandelj
crandelj

asked on

DataList remove span

I've built a custom datalist server control that works beautifully with RepeatLayout = Flow and RepeatDirection = Horizontal except that it still ads the <span> wrapper around the whole control output and also each DataListItem within has a span.

I know there is no default property to turn these spans off so I'd like to know the most elegant way to remove them with my custom control's code (no javascript/jquery solutions please).
Avatar of guru_sami
guru_sami
Flag of United States of America image

I am not sure of removing all spans entirely but to some extent you can manually customize the ItemTemplate.

Other option is to use Repeater insted where you have full control over the rendered html.
Avatar of crandelj
crandelj

ASKER

I don't think there's anything I can do to ItemTemplate that will remove the automatic spans that DataList renders around the items (outside of ItemTemplate).  

I'm thinking maybe overriding the control's render method but I'm not sure.

And for your suggestion of using a Repeater instead, yes that would have been a quick answer to getting rid of the extra spans but unfortunately I have to use a DataList.
Yes...no easy switch to remove outer spans.
If you don't mind what is it that you can only use DataList?
I started building a custom repeater control but could not find a solution to a casting problem at binding (repeateritem to listitem if I recall correctly...).  I had looked around for a solution elsewhere and others had said it was a known issue.  I switched to DataList using essentually the same code and and immediately the problem went away.  

So I'm using the DataList and trying to strip the output so it acts like a repeater.
I don't mind writing some code to remove the spans, but I need to understand what method to override and how to reliably remove the extra spans the DataList adds.

Just as a reminder, when you use a DataList with RepeatLayout=Flow and RepeatDirection=Horizontal it outputs something like this:

<span id="datalistcontrolID">
<span>item1</span>
<span>item2</span>
<span>itemx</span>
</span>

So what I'd like to do is at a minimum remove the spans around the items or even better remove those and also the outside span (but I have the feeling that outside span may be used by ID for preserving something in postback).
@guru_sami  I'll review those links thanks
ASKER CERTIFIED SOLUTION
Avatar of crandelj
crandelj

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
No reliable way to strip extra spans rendered by datalist while leaving valid spans from the itemtemplate was provided in answers.  So I just went back to my original solution of using a custom repeater instead of datalist so I could control the output.