Home » ASP.NET » Converting a DataList to a ListView

Converting a DataList to a ListView

Yesterday, I spent the bulk of the day converting a DataList to a ListView.  I thought I’d spend a little time relating the process for those of you who might be interested in doing the same.

For the most part, the transition went smoothly.

The first thing I looked at was the structure of the two sets of tags.  It was pretty quickly apparent that I was not going to be able to just change the tag name.  Not that I expected I could, but it would have been a nice bonus. 

What I did notice as I inspected the structure was that both sets have an ItemTemplate tag.  So I create a new ListView control pointing at the data I want it to display, and then I moved the itemTemplate tag from the DataList into the new ListView.

Bad move.  But, since I’ve already suffered the pain, it won’t be so bad for you.  The basic problem stems from the fact that the ListView itemTemplate expects to start and end with a pair of TD tags.  In the DataList’s itemTemplate tag, you can put anything you want.  So, what you should do is copy the contents of the itemTemplate tag in the DataList into the the ListView’s itemTemplate tag and then put the TD tags around the content you just pasted, and inside the itemTemplate tags.

Not so bad once you figure it out, but if you start this process after a full day of programming, this can be just a bit frustrating.


Other post in ASP.NET

Related Post

  • ListView and the DataPagerListView and the DataPager One of the new controls that Visual Studio 2008 brings us is the ListView.  Now, the ListView control is really several different controls all rolled into one.  There is a lot to see with […]
  • Sorting the ListView in ASP.NETSorting the ListView in ASP.NET Are you confused about how to implement sorting in the new ListView control in ASP.NET 3.5?  Join me as I show you in this step by step video showing you exactly how to sort a ListView, […]
  • Multi-Step Processing in ASP.NETMulti-Step Processing in ASP.NET I received the following question a few days ago but I’ve been so busy with billable work that I just haven’t had a chance to answer it until now.  Actually, I’m still busy, but I […]
  • GridViews – Multiple Rows Per RecordGridViews – Multiple Rows Per Record I don't know about you, but I've had several occasions where I've needed to use the simplicity of the GridView control in ASP.NET.  DataBinding, Paging, Sorting, etc.  But I've also […]
  • ASP.NET Dynamic ValidatorASP.NET Dynamic Validator One of the controls that was added to ASP.NET 3.5 in the SP1 release was the Dynamic Validator control.I completely missed it.What it does is pretty cool.  But it doesn’t […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer focusing on ASP.NET, C#, Node.js, JavaScript, HTML, CSS, BootStrap, and Angular.JS.Does your team need additional help in any of the above? Contact Dave today.