Solved

DataList remove span

Posted on 2013-01-24
9
1,159 Views
Last Modified: 2013-05-14
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).
0
Comment
Question by:crandelj
  • 6
  • 3
9 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 38816763
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.
0
 

Author Comment

by:crandelj
ID: 38824475
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.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38824544
Yes...no easy switch to remove outer spans.
If you don't mind what is it that you can only use DataList?
0
 

Author Comment

by:crandelj
ID: 38827744
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 41

Expert Comment

by:guru_sami
ID: 38827776
0
 

Author Comment

by:crandelj
ID: 38827787
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).
0
 

Author Comment

by:crandelj
ID: 38827863
@guru_sami  I'll review those links thanks
0
 

Accepted Solution

by:
crandelj earned 0 total points
ID: 39153052
I ended up writing a custom repeater to solve this. There did not seem to be a reliable way to strip invalid spans while leaving valid spans using the datalist control.
0
 

Author Closing Comment

by:crandelj
ID: 39163990
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now