ユーザー コントロールを動的に読み込む Web ページがあります。各ユーザー コントロールは、同じコントロールを再帰的に読み込むことができます。各コントロールには削除ボタンがあります。私が抱えている問題は、ユーザーが削除ボタンをクリックしたときに、削除ボタンが含まれているコントロールを削除する必要があることです。
ページ コントロール コレクションは次のようになります。
Page
Group 1
Category Control
Category Control
Category Control
Category Control
Category Control
Category Control
新しく作成したカテゴリ コントロールを削除するにはどうすればよいですか。私はthis.Disposeを試しましたが、うまくいきません。
追加時にユーザーコントロールを動的にロードするメインページには、次のものがあります。
protected void cmdsubmitsofficecat_Click(object sender, EventArgs e)
{
int retvalue = 0;
SQLConnectivity db = new SQLConnectivity();
SqlParameter[] param = new SqlParameter[8];
List<group.category> flist = new List<group.category>();
param[0] = db.MakeInputParameter("@group_id", 1);
param[1] = db.MakeInputParameter("@parent_id", DBNull.Value);
param[2] = db.MakeInputParameter("@category_name", this.txtofficecat.Text.Trim());
param[3] = db.MakeInputParameter("@description", this.txtofficecat.Text.Trim());
param[4] = db.MakeInputParameter("@organization_id", 1);
param[5] = db.MakeInputParameter("@created_by", 1);
param[6] = db.MakeInputParameter("@is_active", 1);
param[7] = db.MakeOutputIntegerParameter("@category_id");
db.RunNonQueryProcedure("PerformanceCategorySave", param, ref retvalue);
if (retvalue != 0)
{
group.category item = new group.category();
item.catid = retvalue;
item.catname = this.txtofficecat.Text.Trim();
item.desc = this.txtofficecat.Text.Trim();
item.isactive = true;
item.parid = 0;
catctl ctl = (catctl)Page.LoadControl("~/catctl.ascx");
ctl.groupid = 1;
ctl.organizationid = 1;
ctl.categoryid = item.catid;
ctl.categoryname = item.catname;
ctl.parentid = item.parid;
ctl.ctltype = 1;
ctl.clist = item.categories;
ctl.plist = item.points;
this.officephld.Controls.Add(ctl);
this.switch_officefields(false, 1);
}
}
Web ユーザー コントロールには、次のような Page_Load メソッドがあります。
protected void Page_Load(object sender, EventArgs e)
{
Label ctname = (Label)this.FindControl("ctl0_catname");
this.catname.Text = categoryname;
this.cmdaddcat.Attributes.Add("catid", categoryid.ToString());
this.cmddeletecat.ID = "cmddeletecat" + categoryid.ToString();
this.cmddeletecat.Click += new ImageClickEventHandler(this.cmddeletecat_Click);
if ( clist != null && clist.Count > 0 )
{
int i = 0;
this.cmddeletecat.Visible = false;
foreach ( group.category item in clist )
{
catctl ctl = (catctl)Page.LoadControl("~/catctl.ascx");
ctl.categoryid = item.catid;
ctl.categoryname = item.catname;
ctl.organizationid = organizationid;
ctl.groupid = groupid;
ctl.parentid = item.parid;
ctl.clist = item.categories;
ctl.plist = item.points;
ctl.ctltype = ctltype;
this.newphld.Controls.Add(ctl);
}
}
if ( plist != null && plist.Count > 0 )
{
this.rptPts.Visible = true;
this.rptPts.DataSource = plist;
this.rptPts.DataBind();
this.cmddeletecat.Visible = false;
}
this.Switch_Usability();
}
および削除メソッドは次のとおりです。
protected void cmddeletecat_Click(object sender, ImageClickEventArgs e)
{
List<group.category> flist = new List<group.category>();
SQLConnectivity db = new SQLConnectivity();
SqlParameter[] param = new SqlParameter[1];
DataTable dt = new DataTable();
DataTable sdt = new DataTable();
group parent = new group();
param[0] = db.MakeInputParameter("@category_id", categoryid);
db.RunNonQueryProcedure("PerformanceCategoryDelete", param);
if ( Page != null )
{
PlaceHolder ctl = (PlaceHolder)Page.FindControl("officephld");
if ( ctl != null )
{ ctl.Controls.Remove(this); }
}
}