c# - Delete multiple asp.net repeater Items with checkbox selection only -


here not show error page loading 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

you forgot write cmd.executenonquery();

  1. stop using addwithvalue
  2. always use using sqlconnection , sqlcommand implements idisposable

    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)         {       using(sqlconnection con = new sqlconnection(strcon))             {       using(sqlcommand cmd = new sqlcommand("ram", con))              {             cmd.commandtype = commandtype.storedprocedure;             con.open();             cmd.parameters.add("@action",sqldbtype.varchar,50).value="delete";             cmd.parameters.add("@eid",sqldbtype.int).value=convert.toint16(txt_id.text);             cmd.executenonquery();            repeat();             }            }        }                 }      

    }


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -