suthakar

suthakar

  • NA
  • 2
  • 1.7k

delete in repeater control

Dec 18 2012 9:40 AM
 delete control does not work my item template is
<ItemTemplate>
                            <tr>
                                <td id="sno" runat="server"> <%#DataBinder.Eval(Container.DataItem,"ID") %></td>
                                <td><%#Eval("name") %></td>
                                <td class="center"><%#DataBinder.Eval(Container.DataItem,"dateofreg") %></td>
                                <td class="center"><%#DataBinder.Eval(Container.DataItem,"sex") %></td>
                                <td class="center">
                                    <span class="label label-success">pending</span>
                                </td>
                                <td class="center">
                                    <a class="btn btn-success" target="_parent" href="#">
                                        <i class="icon-zoom-in icon-white"></i> 
                                        View                                           
                                    </a>
                                    <a class="btn btn-info" href="#">
                                        <i class="icon-edit icon-white"></i> 
                                        Edit                                           
                                    <asp:Linkbutton ID="linkdelete" runat="server" class="btn btn-danger" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="delete" OnClientClick='javascript:return confirm("Are you sure you want to delete?")' ><i class="icon-trash icon-white"></i> Delete</asp:Linkbutton>
                                   
                                </td>
                            </tr>
                            </ItemTemplate>









and my code behind is:

protected void Repeater1_itemcommand(object source, RepeaterCommandEventArgs e)
    {
        LinkButton linkdelete = (LinkButton)e.Item.FindControl("linkdelete");
        if (e.CommandName == "delete")
        {
            MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["connectionstring"]);

            MySqlCommand cmd = new MySqlCommand(" DELETE FROM registration  WHERE id=@ID;", con);
           
            cmd.Parameters.Add("@ID",MySqlDbType.VarChar).Value=e.CommandArgument;
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                    con.Close();
            }
          
            binddata();
          
        }
    }











Answers (1)