我删除了一个子类别,希望只在按钮点击时绑定。如何停止数据源和重复器在第一次页面加载时进行绑定?
DataTable dtCategory = system.GetDataTable("Select * from TBLCATEGORIES where SubCategoryID=" + CategoryID);
if (dtCategory.Rows.Count > 0)
{
rpCategory.DataSource = dtCategory;
rpCategory.DataBind();
}
if (Process == "Delete")
{
DataTable dtProducts = system.GetDataTable("Select COALESCE(COUNT(1),0) as TOTAL from TBLPRODUCTS where CategoryID = " + CategoryID);
if (dtProducts.Rows[0]["TOTAL"].ToString() == "0")
{
SqlConnection cnn = new SqlConnection("data source=localhost;initial catalog=Optima; Integrated Security=SSPI;");
SqlCommand cmd = new SqlCommand("Delete from TBLCATEGORIES where CategoryID=" + Request.QueryString["CategoryID"] );
try {
cnn.Open();
cmd.Connection=cnn;
cmd.ExecuteNonQuery();
}
catch(Exception ex) {
lblMsg.Text = ex.Message;
}
finally {
cnn.Close();
DeleteMsg.Visible = true;
}
}
else {
InfoMsg.Visible=true;
}