简体   繁体   English

如何在asp.net中停止页面加载的数据绑定

[英]How to stop data binding on page load in asp.net

I delete a subcategory. 我删除了一个子类别。 I want them to bind only on a button click. 我希望它们仅在按钮点击时绑定。 How to stop the datasource and repeater from binding on first page load ? 如何在第一页加载时阻止数据源和转发器绑定?

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

在Page_Load上检查页面是否回传, if(Page.IsPostBack)然后绑定要绑定的数据!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM