如何将项目从一个数据列表传输到另一数据列表?

发布于 2024-12-08 17:46:49 字数 1722 浏览 1 评论 0原文

我有一个数据列表

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

,其中我通过 uplodify 上传上传后绑定图像,现在我还有一个数据列表 和两个 btn 向上和向下,

<asp:ImageButton ID="ibtnMoveUp" runat="server" ImageUrl="~/App_Themes/Default/Images/moveup.bmp"
                        Style="height: 16px" ToolTip="MoveUp The Item" />
<asp:ImageButton ID="ibtnMoveDown" runat="server" ImageUrl="~/App_Themes/Default/Images/movedown.bmp"
                        ToolTip="MoveDown The Item" /> 

<asp:DataList ID="dlstSelectedImages" runat="server" RepeatDirection="Horizontal"
                                RepeatColumns="5" CellSpacing="8">
    <ItemTemplate>
        <asp:ImageButton ID="Image" runat="server" /><br />
        <asp:Label ID="lbl" runat="server" Text="Figure"></asp:Label><%# dlstImage.Items.Count + 1%>
    </ItemTemplate>
 </asp:DataList>

我的两个数据列表位于同一个 webuser 控件中,datalist1 和 datalist2,我有 2 个上下 btn,当我从 datalist1 中选择一个图像并单击向下 btn 时,所选图像应移动到 datalist2。怎么做呢?有人请帮助我,

I have a datalist

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

In which i am binding the image after uploading through uplodify upload, now i have one more datalist
and two btn up and down,

<asp:ImageButton ID="ibtnMoveUp" runat="server" ImageUrl="~/App_Themes/Default/Images/moveup.bmp"
                        Style="height: 16px" ToolTip="MoveUp The Item" />
<asp:ImageButton ID="ibtnMoveDown" runat="server" ImageUrl="~/App_Themes/Default/Images/movedown.bmp"
                        ToolTip="MoveDown The Item" /> 

<asp:DataList ID="dlstSelectedImages" runat="server" RepeatDirection="Horizontal"
                                RepeatColumns="5" CellSpacing="8">
    <ItemTemplate>
        <asp:ImageButton ID="Image" runat="server" /><br />
        <asp:Label ID="lbl" runat="server" Text="Figure"></asp:Label><%# dlstImage.Items.Count + 1%>
    </ItemTemplate>
 </asp:DataList>

My both datalist is in the same webuser control, datalist1 and datalist2 and I have 2 btn up and down, when i select one image from datalist1 and click on down btn then the selected image should move to datalist2. How to do that? someone please help me,

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

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

发布评论

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

评论(2

入画浅相思 2024-12-15 17:46:49

您需要处理 one DataList 的 ItemCommand 事件,在该事件中您必须将所选数据(图像)复制到 two 的另一个数据源中 DataList 并从 one DataList 的数据源中删除该项目。

标记:

<asp:DataList 
            ID="DataList1" 
            runat="server"
            OnItemCommand="PerformMove" 
            >
        <ItemTemplate>
        <br /><%#Eval("Text") %>
        <asp:Button ID="btn1" 
                runat="server" 
                Text="Move"
                CommandName="cmd"
                CommandArgument='<%#Eval("Text") %>'
                />

        </ItemTemplate>
</asp:DataList>
<asp:DataList ID="DataList2" runat="server">
            <ItemTemplate>
            <br /><%#Eval("Text") %>
            </ItemTemplate>
</asp:DataList>

代码隐藏 (.cs)

public class Data
    {
        public string Text { get; set; }
        public override int GetHashCode()
        {
            return Text.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return GetHashCode() == obj.GetHashCode();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<Data> list1 = new List<Data >()
            {
                 new Data() { Text="One"},
                 new Data() { Text="Two"},
                 new Data() { Text="Three"},
            };
            List<Data> list2 = new List<Data>();
            Session["list1"] = list1;
            Session["list2"] = list2;

            DataList1.DataSource = Session["list1"];
            DataList1.DataBind();

            DataList2.DataSource = Session["list2"];
            DataList2.DataBind();
        }
    }
    protected void PerformMove(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "cmd")
        {
            List<Data> list1 = Session["list1"] as List<Data>;
            List<Data> list2 = Session["list2"] as List<Data>;

            list1.Remove(new Data() { Text=e.CommandArgument.ToString() });
            list2.Add(new Data() { Text = e.CommandArgument.ToString() });
            DataList1.DataSource = Session["list1"];
            DataList1.DataBind();

            DataList2.DataSource = Session["list2"];
            DataList2.DataBind();
        }
    }

You need to handle the ItemCommand event of one DataList in which you have to copy the selected data (image) into another dataSource of two DataList and remove that item from the datasource of one DataList.

Markup:

<asp:DataList 
            ID="DataList1" 
            runat="server"
            OnItemCommand="PerformMove" 
            >
        <ItemTemplate>
        <br /><%#Eval("Text") %>
        <asp:Button ID="btn1" 
                runat="server" 
                Text="Move"
                CommandName="cmd"
                CommandArgument='<%#Eval("Text") %>'
                />

        </ItemTemplate>
</asp:DataList>
<asp:DataList ID="DataList2" runat="server">
            <ItemTemplate>
            <br /><%#Eval("Text") %>
            </ItemTemplate>
</asp:DataList>

Code-behind (.cs)

public class Data
    {
        public string Text { get; set; }
        public override int GetHashCode()
        {
            return Text.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return GetHashCode() == obj.GetHashCode();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<Data> list1 = new List<Data >()
            {
                 new Data() { Text="One"},
                 new Data() { Text="Two"},
                 new Data() { Text="Three"},
            };
            List<Data> list2 = new List<Data>();
            Session["list1"] = list1;
            Session["list2"] = list2;

            DataList1.DataSource = Session["list1"];
            DataList1.DataBind();

            DataList2.DataSource = Session["list2"];
            DataList2.DataBind();
        }
    }
    protected void PerformMove(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "cmd")
        {
            List<Data> list1 = Session["list1"] as List<Data>;
            List<Data> list2 = Session["list2"] as List<Data>;

            list1.Remove(new Data() { Text=e.CommandArgument.ToString() });
            list2.Add(new Data() { Text = e.CommandArgument.ToString() });
            DataList1.DataSource = Session["list1"];
            DataList1.DataBind();

            DataList2.DataSource = Session["list2"];
            DataList2.DataBind();
        }
    }
给我一枪 2024-12-15 17:46:49

我正在使用这段代码,它对我来说效果很好。

    ArrayList ImgArry = new ArrayList();
    path = objGetBaseCase.GetImages(TotImgIds);
    ImgArry.Add(SelImgId);
    ImgArry.Add(SelImgpath);//image name
    ImgArry.Add(SelImgName);//image path
    //path.Remove(ImgArry);
    List<ArrayList> t = new List<ArrayList>();
    if (newpath.Count > 0)
        t = newpath;
    t.Add(ImgArry);
    newpath = t;
    for (int i = 0; i < newpath.Count; i++)
    {
        ArrayList alst = newpath[i];
        newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);

    }
    dlstSelectedImages.DataSource = newtb;
    DataBind();

    path = objGetBaseCase.GetImages(TotImgIds);
    for (int i = 0; i < path.Count; i++)
    {
        ArrayList alst = path[i];
        tb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);

    }
    dlstImage.DataSource = tb;
    DataBind();

I am using this code and its working well for me.

    ArrayList ImgArry = new ArrayList();
    path = objGetBaseCase.GetImages(TotImgIds);
    ImgArry.Add(SelImgId);
    ImgArry.Add(SelImgpath);//image name
    ImgArry.Add(SelImgName);//image path
    //path.Remove(ImgArry);
    List<ArrayList> t = new List<ArrayList>();
    if (newpath.Count > 0)
        t = newpath;
    t.Add(ImgArry);
    newpath = t;
    for (int i = 0; i < newpath.Count; i++)
    {
        ArrayList alst = newpath[i];
        newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);

    }
    dlstSelectedImages.DataSource = newtb;
    DataBind();

    path = objGetBaseCase.GetImages(TotImgIds);
    for (int i = 0; i < path.Count; i++)
    {
        ArrayList alst = path[i];
        tb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);

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