删除多个带有复选框选择的asp.net转发器 [英] Delete multiple asp.net repeater with checkbox selection only

查看:82
本文介绍了删除多个带有复选框选择的asp.net转发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处不显示任何错误页面加载。错误在哪里?



C#代码

Here it does not show any error only page loading. Where is the error ?

C# code

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.code

<asp:ImageButton ID="imgs" runat="server" ImageUrl="images/Button-Close-icon.png" OnClick="imgs_Click" />

推荐答案

我们是否在txt_id字段中获取了值?它不应该像Convert.ToString(txt_id.Text)。
Are we getting the value inside txt_id field? It shouldn't be like Convert.ToString(txt_id.Text).


foreach(RepeaterItem ri in repeater.Items)

{



CheckBox item_check =(CheckBox)ri.FindControl(item_check);

标签txt_id =(标签)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);

试试

{

con.Open();

cmd.ExecuteNonQuery();



}

catch(Excepti在前)

{

ex.Message.ToString();

}

终于

{



con.Close();

}

}

}

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


这篇关于删除多个带有复选框选择的asp.net转发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆