2011-03-11 128 views
0

我有一个列表视图显示图像像ImageViewer,我想在ListView中实现拖放行为。请让我知道如何在下面这种定制的ListView中实现Srag-Drop。在ASP.Net中的ListView中拖放项目

<asp:ListView ID="lvPhotoViewer" runat="server" GroupItemCount="3" InsertItemPosition="LastItem"> 
    <LayoutTemplate> 
     <table id="groupPlaceholderContainer" runat="server" border="1"> 
      <tr id="groupPlaceholder" runat="server"> 
      </tr> 
     </table> 
    </LayoutTemplate> 
    <ItemTemplate> 
     <td id="Td4" align="center" style="background-color: #eeeeee;"> 
      <asp:Image runat="server" ID="imPhoto" Height="100px" Width="100px" ImageUrl='<%# "~"+Eval("PhotoUrl") %>' /> 
      <br /> 
      <asp:Label ID="DefaultPhotIDLabel" runat="server" Text='<%# Eval("PhotoName") %>' /> 
     </td> 
    </ItemTemplate> 
    <GroupTemplate> 
     <tr id="itemPlaceholderContainer" runat="server"> 
      <td id="itemPlaceholder" runat="server"> 
      </td> 
     </tr> 
    </GroupTemplate> 
    <InsertItemTemplate> 
     <td id="Td3" width="150px" height="150px" runat="server" align="center" style="background-color: #e8e8e8; 
      color: #333333;"> 
      <asp:FileUpload ID="fileUpload" runat="server" /> 
     </td> 
    </InsertItemTemplate> 
</asp:ListView>              

代码背后:

public class ImageEntity 
{ 
    public string PhotoName { get; set; } 
    public int PhotoIndex { get; set; } 
    public string PhotoURL { get; set; } 
} 


public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     IList<ImageEntity> imagesList = new List<ImageEntity>() 
     { 
      new ImageEntity(){ PhotoName="House1", PhotoIndex=1, PhotoURL= @"\Images\House-01.JPG" }, 
      new ImageEntity(){ PhotoName="House2", PhotoIndex=2, PhotoURL= @"\Images\House-05.JPG" }, 
      new ImageEntity(){ PhotoName="House3", PhotoIndex=3, PhotoURL= @"\Images\house.jpg" }, 
      new ImageEntity(){ PhotoName="House4", PhotoIndex=4, PhotoURL= @"\Images\house2.jpg" } 
     }; 

     lvPhotoViewer.DataSource = imagesList; 
     lvPhotoViewer.DataBind(); 
    } 
} 

请给我建议的方式来实现的ListView

+0

你想拖放...什么?哪里?你想排序的图像,或..? – 2011-03-11 15:08:30

+0

我有一个listview控件,里面我使用ItemTemplate显示图像。现在我想Draog将这些图像放在自己内部,以重新排列列表视图中的图像。我想使用拖放重新排序图像。 – 2011-03-13 04:22:27

回答

2

考虑使用jQuery拖内拖放的图像/下降UI功能:http://jqueryui.com/demos/draggable/http://jqueryui.com/demos/droppable/

另外,如果你想拖/放行,检查了这一点:jQuery draggable table elements

HTH。

+0

感谢大脑..解决方案看起来很完美,但小示范应用程序真的有帮助。我对JQuery非常陌生,所以如果可能的话,请你指点一个示例应用程序,其中Listview中的图像可以被拖放? – 2011-03-13 04:19:34

+0

大脑,你给出的链接确实有帮助。我能够用它实现Drag-dRop功能.. – 2011-03-19 03:59:21