如何在移动到datalist2后禁用datalist1中的图像?

时间:2011-10-12 09:13:18

标签: c# asp.net datalist

我有2个datalist和2个btn UP和Down,我试图将所选图像从一个datalist移动​​到其他datalist。

Datalist1:

  <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")+";"+Eval("FileName") %>' /><br />
         <asp:Label ID="lbl" runat="server" Text="Figure"></asp:Label><%# dlstImage.Items.Count + 1%>
     </ItemTemplate>
   </asp:DataList>

按钮:

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

Datalist2:

   <asp:DataList ID="dlstSelectedImages" 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="ImageSelect_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
           <asp:Label ID="nlbl" runat="server" Text="Figure"></asp:Label><%# dlstSelectedImages.Items.Count + 1%>
       </ItemTemplate>
     </asp:DataList>

按下按钮代码:

        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();

我正在从datalist1中选择一个图像并传输到datalist2,我能够将图像从一个数据主义者移动到其他数据主义者,但我想要的是当我移动图像然后Datalist1图像时,我正在移动那个图像移动到datalist2后,图像在Datalist1中被禁用,如何做到这一点,如何在移动到datalist2后禁用datalist1中的图像。

2 个答案:

答案 0 :(得分:0)

你可能需要在适当的时候调用DataBind()方法,这是在加载两个单独的数组之后

DataList1.DataBind(); DataList2.DataBind();

如果我找到你的话,这应该可以正常工作

答案 1 :(得分:0)

protected void dlstImage_ItemDataBound(object sender, DataListItemEventArgs e)// for disabling the image after moving
    {
        ImageButton imgctrl = (e.Item.FindControl("Image") as ImageButton);
        string[] str = imgctrl.CommandArgument.ToString().Split(';');
        SelImgId = Convert.ToInt32(str[0]);
        if (newpath.Exists(delegate(ArrayList imageDetails) { return Convert.ToInt32(imageDetails[0]) == SelImgId; }))
        {
            imgctrl.Enabled = false;
            imgctrl.CssClass = "tdDisable";
        }
        else
        {
            imgctrl.Enabled = true;
            imgctrl.CssClass = "";
        }
    }