[英]How to stop data binding on page load in asp.net
我刪除了一個子類別。 我希望它們僅在按鈕點擊時綁定。 如何在第一頁加載時阻止數據源和轉發器綁定?
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.