我删除了一个子类别。我希望它们仅在按钮点击时绑定。如何在第一页加载时阻止数据源和转发器绑定?
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;
}
答案 0 :(得分:0)
on Page_Load检查页面是回发还是不if(Page.IsPostBack)
然后绑定要绑定的数据!