开发者

How to change the order of datalist images from left to right or right to left?

开发者 https://www.devze.com 2023-04-13 05:52 出处:网络
I have a datalist and 2 button life right which is outside of datalist datalist: <asp:DataList ID=\"dlst\" runat=\"server\" RepeatDirection=\"Horizontal\"

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

datalist:

<asp:DataList ID="dlst" runat="server" RepeatDirection="Horizontal"
             开发者_如何学Python                   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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号