aleksandar ruba

aleksandar ruba

  • NA
  • 33
  • 25.5k

checkbox and datalist

May 17 2012 9:10 AM
Good day to all.
I have datalist and checkbox in my web page.Datalist display a image from one folder,in datalist is a checkbox with the name of image.
I won't delete a image where checkbox is checked pushing a button but i can't catch it.IF you now please help my,i be gratefull.
there is the code and sorry for my english.

<asp:DataList ID="DataList1" runat="server">
                <ItemTemplate>
                    <div style="margin: 10px; float: left;">
                        <img alt="" src="../slike/<%# Eval("slika") %>" width="100" height="100" /><br />
                       <asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Eval("ime") %>' /> 
        
                    </div>
                </ItemTemplate>
                <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            </asp:DataList>
            <asp:Button ID="Button3" runat="server" Text="Button" onclick="Button3_Click" /> 




 protected void Button3_Click(object sender, EventArgs e)
    {
       
       
        foreach (DataListItem li in DataList1.Items)
        {
            
            CheckBox cb = (CheckBox)li.FindControl("CheckBox1");
            if (cb.Checked)
            {
                File.Delete(Server.MapPath("~/slike/" + cb.Text ));
            }
               
            

        } 
       
        pokazislike();
    }

thx in advance