This article explains how to make the
datalist items automatically adjustable like
div elements in HTML using JQuery and CSS as shown in the following image:
Using the Code
div, when you give style
float:left and give a
width, then the
div will adjust automatically into the container whenever you remove any in between
When you are using datalist to display image listing and using JQuery to delete any image, then if you delete any in between image then the page will not get refreshed and the image will be deleted but it will display the empty space there as follows. You can see the empty space in the second line right most in the following image.
The reason behind this is that the default value for the '
RepeatLayout' property is '
Table'. It means the items are in
td layout. So it can't move automatically like
Now let us talk about the solution:
And then write the JQuery code as follows:
- Make the '
RepeatLayout' property of datalist '
Flow' as in the following example:
- By this property, the datalist item will be converted into
span elements rather than
- And also remove
- HTML tag:
<asp:DataList ID="dlPhotos" runat="server"
DataSourceID="sqlListing" RepeatDirection="Vertical" RepeatLayout="Flow">
- Add class to datalist for hide tags like:
- Now give any class name to an
ItemStyle tag of the
First, please add latest JQuery file in your page. You can download it from here OR here.
var tdImg = $("#<%=dlPhotos.ClientID%> .tdContainer");
- So it will give
150px to all the
span elements and also give
float:left property, So now when you delete any in between image then all the
span elements will align automatically.
Do the above four steps and enjoy......
• 3.6 years of experience in IT industry
• 3.6 years of Experience in Web technologies including ASP.net.
• Hands-on experience in Technologies including DotNet 2003/2005 (C# & VB.net) – MVC Framework, MS SQL server 2003/2005/2008, java script, jQuery, Ajax, CSS, SVN, VSS.
• Hands on experience on working in N-Tire Architecture.
• Experience in HTML, DHTML, XML, CSS.
• A quick learner and good management, analytical and database designing skill.
• Experience in Application Servers including IIS 5.0/6.0/7.0