如何在ASP.NET中阻止页面加载时的数据绑定

3

我删除了一个子类别,希望只在按钮点击时绑定。如何停止数据源和重复器在第一次页面加载时进行绑定?

 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;
                }

通过检查IsPostback? - Tab Alleman
当我添加了PostBack后,删除数据后就看不到数据了。 - Shqiptar
1个回答

0
在 Page_Load 事件中检查页面是否为 PostBack:if(Page.IsPostBack),然后绑定你想要绑定的数据!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接