Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here it does not show any error only page loading. Where is the error ?

C# code
C#
protected void imgs_Click(object sender, ImageClickEventArgs e)  
        {        
            foreach (RepeaterItem ri in repeater.Items)
            {
               
                CheckBox item_check = (CheckBox)ri.FindControl("item_check");
                Label txt_id = (Label)ri.FindControl("txt_id");
                
                    if (item_check.Checked)
                    {
                        con = new SqlConnection(strcon);
                        SqlCommand cmd = new SqlCommand("ram", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        con.Open();
                        cmd.Parameters.AddWithValue("@Action", "DELETE");
                        cmd.Parameters.AddWithValue("@eid", txt_id);
                        repeat();
                   }                
            }     
    }

asp.code
ASP.NET
<asp:ImageButton ID="imgs" runat="server" ImageUrl="images/Button-Close-icon.png" OnClick="imgs_Click" />
Posted
Updated 1-Dec-14 20:36pm
v2
Comments
Sinisa Hajnal 2-Dec-14 3:17am    
What error? What happens when you run the code? What is happening in repeat() function? Where are you executing your command?
Member 10918596 2-Dec-14 4:39am    
i m getting this error Collection was modified; enumeration operation may not execute.

Are we getting the value inside txt_id field? It shouldn't be like Convert.ToString(txt_id.Text).
 
Share this answer
 
Comments
Member 10918596 2-Dec-14 4:39am    
i m getting this error Collection was modified; enumeration operation may not execute.
Badal Kumar 2-Dec-14 4:59am    
Use for loop rather then using the foreach.
foreach (RepeaterItem ri in repeater.Items)
{

CheckBox item_check = (CheckBox)ri.FindControl("item_check");
Label txt_id = (Label)ri.FindControl("txt_id");

if (item_check.Checked)
{

con = new SqlConnection(strcon);
cmd = new SqlCommand("ram", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Action", "DELETE");
cmd.Parameters.AddWithValue("@eid", txt_id.Text);
try
{
con.Open();
cmd.ExecuteNonQuery();

}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{

con.Close();
}
}
}
repeat();
 
Share this answer
 

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