Solved

DataList remove span

Posted on 2013-01-24
9
1,140 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

18 Experts available now in Live!

Get 1:1 Help Now