Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
<asp:DataList ID="DataList1" runat="server" BackColor="White"
            BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" RepeatColumns="4"
            RepeatDirection="Horizontal" CellSpacing="1"
            onselectedindexchanged="DataList1_SelectedIndexChanged">
            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            <ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
        <ItemTemplate>
        <table class="table" align="center">
<tr>
<td>
    <asp:Image ID="Image1" runat="server" Height="80px" Width="100px" ImageUrl='<%#Eval("IMAGE")%>' /><br />
    <asp:Label ID="Label1" runat="server" Text='<%#Eval("IMAGE_NAME") %>' />&nbsp;&nbsp;&nbsp;
    <asp:CheckBox ID="deleteRec" runat="server" />
        <asp:TextBox ID="ImageID" runat="server" Text='<%#Eval("IMAGE_ID") %>' Visible="false"></asp:TextBox>
</td>
</tr>
</table>
        </ItemTemplate>
            <SelectedItemStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
        </asp:DataList>





CS file code

protected void Button2_Click(object sender, EventArgs e)
        {
            //StringCollection idCollection = new StringCollection();

            bool isDeleted = false;
         
            foreach (DataListItem anItem in DataList1.Items)
            {
                CheckBox chk = ((CheckBox)anItem.FindControl("deleteRec"));
               
            
                isDeleted = chk.Checked;

                TextBox tmpTxtBox = ((TextBox)anItem.FindControl("ImageID"));
                string imageID = tmpTxtBox.Text;
                if (isDeleted)
                {
                    proxy.DeleteRecord("delete from Image where IMAGE_ID=" + imageID + "");
                }
            }






my problem is checkbox always give false result even i select checkbox.

plz help me
Thanks in advance.
Posted
Updated 26-Jul-11 23:02pm
v4

try this,

foreach (DataListItem anItem in DataList1.Items)
        {
            CheckBox chk = ((CheckBox)anItem.FindControl("deleteRec"));
            if (chk != null)
            {
                if (chk.Checked)
                {
                    TextBox tmpTxtBox = ((TextBox)anItem.FindControl("ImageID"));
                    string imageID = tmpTxtBox.Text;
                    proxy.DeleteRecord("delete * from Image where IMAGE_ID=" + imageID + "");
                }
            }
        }
 
Share this answer
 
my problem is checkbox always give false result even i select checkbox.

i have tried all the above code.
i hve done enable view state =true , too
but i did't get the answer.

anyone plzz help me out.........
 
Share this answer
 
I guess this is a viewstate Issue am not sure, but has the page directive marked enable viewstate to false,

If yes try changing it to true.

Regards,
Nitin Verma
 
Share this answer
 
Comments
Pravinjas 27-Jul-11 4:57am    
Thanks.Its working.........I have done EnableViewState="false"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900