使用ajax重排序列表对数据库列进行排序不起作用? [英] Sorting database columns using ajax reorder list not working well ?

查看:63
本文介绍了使用ajax重排序列表对数据库列进行排序不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在数据库中有一个名为products的表.在其中我有:(productid,productname,productsort.).我正在使用重排序列表使用productsort字段对数据库中的这些项目进行排序.但是数据库中的更新不是好吧,因为这些值的顺序与重新排序列表中的顺序不同.例如,如果我将具有sort = 1的product1放在具有sort = 2的product2下.数据库中的值不会成为product1和sort-的sort = 2产品2的1.这是我的代码:

Hi all ,

I have a table in the database called products.And in it i have :(productid,productname,productsort.).I am using reorder list to sort those itms in the database using the productsort field.But the update in the database is not well,since the values are not in the same order of those in the reorderlist.For example if i put product1 with sort=1 under product2 with sort=2.The values in the database are not becoming sort=2 for product1 and sort-1 for product2.And here is my code :

<div class="ajaxOrderedList">
    <asp:ReorderList ID="ReorderList1" runat="server" AllowReorder="True" DataSourceID="ObjectDataSource1"

        DataKeyField="Product_Id" DragHandleAlignment="Left" SortOrderField="Product_Sort"

        PostBackOnReorder="false">
        <EditItemTemplate>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </EditItemTemplate>
        <ReorderTemplate>
            <div style="width: 300px; height: 20px; border: dotted 2px black;">
            </div>
        </ReorderTemplate>
        <ItemTemplate>
            <div>
                <asp:Label ID="Label1" BackColor="Blue" runat="server" Text='<%# Eval("Product_Title")%>'

                    ForeColor="Wheat" Width="300px"></asp:Label></div>
        </ItemTemplate>
        <DragHandleTemplate>
            <div style="height: 20px; width: 20px; border: solid 1px black; background-color: Red;
                cursor: pointer;">
            </div>
        </DragHandleTemplate>
    </asp:ReorderList>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete"

        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"

        TypeName="Sorting.DsTableAdapters.ProductsTableAdapter" UpdateMethod="Update">
        <DeleteParameters>
            <asp:Parameter Name="Original_Product_Id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Product_Title" Type="String" />
            <asp:Parameter Name="Product_Sort" Type="Int32" />
            <asp:Parameter Name="Original_Product_Id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Product_Title" Type="String" />
            <asp:Parameter Name="Product_Sort" Type="Int32" />
        </InsertParameters>
    </asp:ObjectDataSource>
    <asp:Button ID="Buttonupdate" runat="server" Text="update" />
</div>



那么解决方案是什么?

谢谢.



So what is the solution ?

Thanks.

推荐答案

我找到了.我应该在查询中输入by,所以对于遇到我问题的任何人,请在查询中输入by.字段应与SortOrderField
i found it.I should put order by in my query,so for anyone facing my problem please put order by in your query.And the order by field should be the same as the SortOrderField


这篇关于使用ajax重排序列表对数据库列进行排序不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆