Click here to Skip to main content
15,893,564 members
Articles / Web Development / HTML
Article

How to implement JQuery UI Sortable in DataList Control ?

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Oct 2013CPOL2 min read 9.5K   1  
Basically when DataList is rendered HTML in Table and like below   HTML Code placed at ItemTemplate

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.


Basically when DataList is rendered HTML in Table and like below 
<table>
<tr>
  <td> HTML Code placed at ItemTemplate </td>
</tr>

</table>

But UI sortable can be apply on <tbody>, so we need to add tbody on the above table to implement Jquery UI Sortable.

But now how we can inject tbody in to a DataList ? it’s too simple to do that.

<asp:DataList ID="dlList" runat="server" >
        <HeaderTemplate>
<tbody>
</HeaderTemplate>
        <ItemTemplate>
</ItemTemplate>       
        <FooterTemplate>
</tbody>
</FooterTemplate>
</asp:DataList>
     
By adding  <tbody> start tag at HeaderTemplate and </tbody> end tag at the FooterTemplate we can inject the <tbody> in the DataList .
 After adding the tbody in Header & Footer Template the rendered HTML become will be
<table>
<tbody>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>

Now we can easily implement JQuery UI Sortable in the DataList below the Jquery implementation.
For that you need to add below Js in your application 
 
$(function () {
             $("#<%=dlProcessList.ClientID %> tbody").sortable({
                 handle: ".handle",
                 helper: tableRowHelper,
                 placeholder: 'ui-state-highlight',
                 cursor: 'move',
                 start: function (event, ui) {
                     ui.placeholder.height(ui.helper.height());
                 }
             }).disableSelection();
         });        

<asp:DataList ID="dlList" runat="server" >
        <HeaderTemplate>
<tbody>
</HeaderTemplate>
        <ItemTemplate>
// insert code to display required data
</ItemTemplate>       
        <FooterTemplate>
</tbody>
</FooterTemplate>
</asp:DataList>

Enjoy Coding :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
-- There are no messages in this forum --