【问题标题】:How to remove subcategory in recursive function? asp.net如何删除递归函数中的子类别?网
【发布时间】:2016-05-30 10:49:55
【问题描述】:

我正在尝试使用链接按钮从转发器中删除子类别。目前,主要类别已删除,但我无法删除子类别。请帮帮我...

    private void BindRepeater()
    {
        DataTable dtCategory = system.GetDataTable("Select * from TBLCATEGORIES where SubCategoryID="+CategoryID); 

        if (dtCategory.Rows.Count > 0)
        {
            rpCategory.DataSource = dtCategory;
            rpCategory.DataBind();
        }
    }

    protected void OnDelete(object sender, EventArgs e)
        {
    //Find the reference of the Repeater Item.
    RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem;


    string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        SqlCommand cmd = new SqlCommand("Delete from TBLCATEGORIES where SubCategoryID="+CategoryID); 
        {
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            DeleteMsg.Visible = true;
        }
    }
    this.BindRepeater();
}

【问题讨论】:

  • 只有删除的行是Repeater中的唯一行时才会出现问题,还是Repeater中有几行时也会出现问题?

标签: c# sql asp.net sql-server-2008


【解决方案1】:

请找到代码,希望对您有所帮助:

   protected void rpCategory_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
            SqlConnection conn;
            SqlCommand comm;
            string connectionString = ConfigurationManager.ConnectionStrings["ShqiptarConnectionString"].ConnectionString;
            conn = new SqlConnection(connectionString);

            conn.Open();

            if (e.CommandName == "Delete")
            {
            comm = new SqlCommand("Delete from TBLCATEGORIES where CategoryID=" + e.CommandArgument, conn);
            comm.ExecuteNonQuery();
            }

            conn.Close();
            conn.Dispose();
            DeleteMsg.Visible = true;

           //Rebind here: this.BindRepeater();
    }

【讨论】:

  • 请通过以下参考 [链接] aspsnippets.com/Articles/… 我们有一个工作示例。
  • 您可以编写一个函数并在您的过程中调用该函数。
猜你喜欢
  • 1970-01-01
  • 2011-12-02
  • 2011-01-24
  • 1970-01-01
  • 1970-01-01
  • 2021-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多