Cyberoxy 0 Newbie Poster

Hey there

I need this problem to be solved.

These ListItem controls should display images when you select item. When I debug it, the image flash blank. I cannot find incorrect codes.

Look at bold codes below:

Markup:

<form id="Form1" method="post" runat="server">
                        <asp:ListBox Runat="server" ID="dlist1" SelectionMode="Multiple"
                           onchange="swapImage1()">
                            <asp:ListItem Value="../Images/photo1.jpg">Photo 1</asp:ListItem>
                            <asp:ListItem Value="../Images/photo2.jpg">Photo 2</asp:ListItem>
                            <asp:ListItem Value="../Images/photo3.jpg">Photo 3</asp:ListItem>
                            <asp:ListItem Value="../Images/photo4.jpg">Photo 4</asp:ListItem>
                        </asp:ListBox>
                        <asp:Button Runat="server" ID="btnMoveRight" Text=" Add To Cart >> "
                            onclick="btnMoveRight_Click"></asp:Button>
                        <asp:Button Runat="server" ID="btnMoveLeft" Text=" Remove << "
                            onclick="btnMoveLeft_Click"></asp:Button>
                        <asp:ListBox Runat="server" ID="dlist2" SelectionMode="Multiple"></asp:ListBox>
                        
                        <div>
[B]                            <asp:Image ID="imageToSwap1" runat="server" width="147" height="195" /> [/B]

                        </div>
                </form>

[B]Javascript (display image when selected item):[/B]

<script type="text/javascript>

function swapImage1() {
    var image = document.getElementById("imageToSwap1");
    var dropd = document.getElementById("dlist1");
    image.src = dropd.value;
};

</script>

Code behind (C#) - when you select item and click button to add to another listbox.

protected void btnMoveRight_Click(object sender, EventArgs e)
    {
        for (int i = dlist1.Items.Count - 1; i >= 0; i--)
        {
            if (dlist1.Items[i].Selected == true)
            {
                dlist2.Items.Add(dlist1.Items[i]);
                ListItem li = dlist1.Items[i];
                dlist1.Items.Remove(li);
            }
        }

    }
    protected void btnMoveLeft_Click(object sender, EventArgs e)
    {
        for (int i = dlist2.Items.Count - 1; i >= 0; i--)
        {
            if (dlist2.Items[i].Selected == true)
            {
                dlist2.Items.Add(dlist2.Items[i]);
                ListItem li = dlist2.Items[i];
                dlist2.Items.Remove(li);
            }
        }              
    }

Your help much appreciated. Thank you!! :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.