如何更改数据列表图像的顺序从左到右或从右到左?

发布于 2024-12-09 18:47:02 字数 1318 浏览 1 评论 0原文

我有一个数据列表和 2 个按钮生命权,位于数据

列表之外:

<asp:DataList ID="dlst" runat="server" RepeatDirection="Horizontal"
                                RepeatColumns="5" CellSpacing="8">
         <ItemTemplate>
                   <asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/Showimg.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'  OnCommand="ImageSelect_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
                  <asp:Label ID="nlbl" runat="server" Text="Figure"></asp:Label><%# dlst.Items.Count + 1%>
            </ItemTemplate>
 </asp:DataList>

按钮:

<asp:ImageButton ID="btnleft" runat="server" ImageUrl="~/images/arrowLBlue.png"
                                ToolTip="Move Item Left"  OnClick="btnleft_Click" />
<asp:ImageButton ID="btnright" runat="server" ImageUrl="~/images/arrowRBlue.png"
                                ToolTip="Move Item Right"  /> 

我正在上传和绑定图像,其工作正常,现在我想在单击按钮时将选定的图像从左向右或从右向左移动,假设我有图像 a1、a2、a3、a4、a5,并且在选择图像 a2 后单击了 btnmoveright 那么图像顺序应该是 a1、a3、a2、a4、a5 现在如果我再次单击btn选择图像a2后向右移动,那么顺序应该是a1,a3,a4,a2,a5,像这样我想移动图像。 怎么做呢?请有人帮助我

I have a datalist and 2 button life right which is outside of datalist

datalist:

<asp:DataList ID="dlst" runat="server" RepeatDirection="Horizontal"
                                RepeatColumns="5" CellSpacing="8">
         <ItemTemplate>
                   <asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/Showimg.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'  OnCommand="ImageSelect_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
                  <asp:Label ID="nlbl" runat="server" Text="Figure"></asp:Label><%# dlst.Items.Count + 1%>
            </ItemTemplate>
 </asp:DataList>

buttons:

<asp:ImageButton ID="btnleft" runat="server" ImageUrl="~/images/arrowLBlue.png"
                                ToolTip="Move Item Left"  OnClick="btnleft_Click" />
<asp:ImageButton ID="btnright" runat="server" ImageUrl="~/images/arrowRBlue.png"
                                ToolTip="Move Item Right"  /> 

I am uploading and binding the images its working fine, now I want to move a selected image from left to right or right to left on my button click, suppose i have image a1, a2, a3, a4, a5 and i clicked on btnmoveright after selecting the image a2 then the image order should be a1,a3,a2,a4,a5 now if again i clicked on btnmoveright after selecting the image a2 then order should be a1,a3,a4,a2,a5 like this I want to move the image.
How to do that? Please someone help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你到最终 2024-12-16 18:47:02

看起来数据列表的数据源是表示文件路径的字符串的集合。如果是这样,只需将所选项目与左侧或右侧的项目交换并重新绑定即可。

Public Sub Swap(ByVal obj1 As Object, ByVal obj2 As Object)
   Dim temp As Object = obj1
   obj1 = obj2
   obj2 = temp
End Sub

您可以将集合存储在视图状态或会话对象中,以便在回发后轻松重新实例化它,而无需重新查询原始源。

It looks like the datasource for your datalist is a collection of strings representing the filepaths. If so, just swap the selected item with the one to the left or the right and rebind.

Public Sub Swap(ByVal obj1 As Object, ByVal obj2 As Object)
   Dim temp As Object = obj1
   obj1 = obj2
   obj2 = temp
End Sub

You can store the collection in the viewstate or in a session object to reinstantiate it easily after postback without requerying the original source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文