Solved

DataList remove span

Posted on 2013-01-24
9
1,174 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

825 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