weixin_33701294 2011-09-17 13:05 采纳率: 0%
浏览 44

asp.net ajax之类的重新排序列表

I'm trying to create a draggable list to change the order some pictures are displayed in a product page. I wan't to be able to do this in the product edit page (same place where I add the pics and their description). So, when creating I have nothing inserted on the database and since the AJAX toolkit reorderlist only works with a datasource I was specifying the list as the source of the reorderlist and calling the databind method. In the item template of the reorder list I have a textbox to edit the pic description and a img that displays the photo. I can drag the items and the list gets reordered, however when I click save I can't get the updated text on the textbox and the order property on the picture doesn't get updated. I've tried manually getting the items in the reorderlist but they're always null even though the list shows 20 items the DataItem is empty. I've enabled viewstate and didn't help either.

Here's my code:

<ajaxToolkit:ReorderList ID="rdlPhotos" runat="server" SortOrderField="PhotoOrder" AllowReorder="true" PostBackOnReorder="true" ClientIDMode="AutoID" EnableViewState="true" ViewStateMode="Enabled">
            <ItemTemplate>
                <div>
                <%--<eva:PhotoView ID="iPV" runat="server" Photo='<%# Container.DataItem %>' />--%>
                    <asp:Image ID="imgPhoto" runat="server" ImageUrl='<%# string.Format("http://eva-atelier.net/sparkle{0}", Eval("Path").ToString().Substring(1)) %>' Width="150" Height="150" />
                    <div class="formGrid">
                        <label class="formLabel">Title</label>
                        <asp:TextBox ID="txtTitle" runat="server" Text='<%#Bind("FileTitle") %>' />
                        <br />
                        <label class="formLabel">Description</label>
                        <asp:TextBox ID="txtDescription" runat="server" Text='<%#Bind("FileDescription") %>' />
                        <br />
                    </div>
                    <p>
                        <asp:Button ID="btnRemove" runat="server" Text="Remover" />
                    </p>
                </div>
            </ItemTemplate>
            <ReorderTemplate>
                <asp:Panel ID="pnlReorder" runat="server" />
            </ReorderTemplate>
            <DragHandleTemplate>
                <div style="width:20px;height:20px;background-color:Red"></div>
            </DragHandleTemplate>
        </ajaxToolkit:ReorderList>

And below the C# code:

private void AddPhotosView()
        {
            if (_currentProduct.Photos != null && _currentProduct.Photos.Count > 0)
            {
                rdlPhotos.DataSource = _currentProduct.Photos;
                rdlPhotos.DataBind();
            }
        }

I'm new to Asp.net I come from a large WPF background, sorry if I'm making basic question :)

Thanks

  • 写回答

1条回答 默认 最新

  • weixin_33698043 2011-09-17 16:22
    关注

    For updating order of ReorderList items add your handler for it's OnItemReorder event. In this case your handler may looks like this:

    protected void ReorderHandler(object sender, ReorderListItemReorderEventArgs  e)
    {
        var movedPhoto = _currentProduct.Photos[e.OldIndex];
        _currentProduct.Photos.RemoveAt(e.OldIndex);
        _currentProduct.Photos.Insert(e.NewIndex, movedPhoto);
        _currentProduct.Photos.Save();
    }
    

    For updating FileTitle and FileDescription of single Photo it is easy to use OnUpdateCommand event of ReorderList and a button with attribute CommandName="Update" for each Photo. And for updating all Photos at once just iterate through rdlPhotos.Items in next manner:

    protected void SaveAllHandler(object sender, EventArgs e)
    {
        foreach (var riItem in rdlPhotos.Items)
        {
            var id = ((HiddenField)riItem.FindControl("itemID")).Value;
            var title = ((TextBox)riItem.FindControl("txtTitle")).Text;
            var description = ((TextBox)riItem.FindControl("txtDescription")).Text;
    
            UpdatePhoto(id, title, description);
        }
    }
    

    Remember that rdlPhotos.Items here are in initial order. And for identifying which Photo should be updated add hidden field with Photo.ID-value to ReorderList's ItemTemplate like this:

    <asp:HiddenField runat="server" ID="itemID" Value='<%# Eval("ID") %>' />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误