2017-04-06 54 views
0

我有一个2下拉列表与公司名称和公司地址和一个删除按钮链接到存储过程。即使我在该地址下拉列表中调用databind(),地址也没有被刷新。任何人都可以向正确的方向指出我吗?asp.net Dropdownlist删除后不刷新

//Button to remove Company 
    protected void btnremovecompany_2(object sender, EventArgs e) 
    { 
     if (ddlcompanyaddress2.SelectedIndex != 0) /*checked to see if an address is Selected first*/ 
     { 
      string confirmValue = Request.Form["confirm_value"]; 
      if (confirmValue == "Yes")/* if yes is clicked then procedd to deactivate that company address*/ 
      { 
       String strConnString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; 
       SqlConnection con = new SqlConnection(strConnString); 
       SqlCommand cmd = new SqlCommand(); 
       cmd.CommandType = CommandType.StoredProcedure; 
       cmd.CommandText = "usp_update_company_active"; 
       cmd.Parameters.Add("@companyname", SqlDbType.VarChar).Value = ddlcompany2.SelectedItem.Text.Trim(); 
       cmd.Parameters.Add("@address", SqlDbType.VarChar).Value = ddlcompanyaddress2.SelectedItem.Text.Trim(); 
       cmd.Parameters.Add("@category", SqlDbType.VarChar).Value = ddlTrades2.SelectedItem.Text.Trim(); 
       cmd.Connection = con; 
       **ddlcompanyaddress2.DataBind();** 
       try 
       { 
        con.Open(); 
        cmd.ExecuteNonQuery(); 

       } 
       catch (Exception ex) 
       { 
        throw ex; 
       } 
       finally 
       { 
        /*Display message saying company is deactivated*/ 
        string message = "Company has been removed"; 
        string script = "window.onload = function(){ alert('"; 
        script += message; 
        script += "')};"; 
        ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true); 
        con.Close(); 
        con.Dispose();       
       }      
      } 
      else 
      { 
       /*if canceled is clicked then display no changes*/ 
       this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('No Changes were made!')", true); 
      } 
     } 
     else 
     { 
      string message = "Please pick an address first."; 
      string script = "window.onload = function(){ alert('"; 
      script += message; 
      script += "')};"; 
      ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true); 
     } 

    } 
+0

可能是您的proc名称暗示了更新而不是删除,再加上您在执行proc之前绑定了列表。 –

+0

@DaveBecker所以databind不能在更新上工作?我在try {}中移动了数据绑定(),但它仍然不起作用。 –

+0

storedproc从数据库中删除数据?下拉列表的数据来源是什么?你是否将page_load中的下拉列表绑定到数据源? –

回答

0

您可能会遗漏下拉列表的数据源。我无法在您的代码中找到数据源。你刚刚称为数据绑定方法。 你可以绑定数据源吗?

0

将此代码添加到try {}区域,并重置所有带有新数据的下拉列表。

ddlgettrades2(); 
getcompany2(ddlTrades2.SelectedItem.Text); 
getaddress2(ddlcompany2.SelectedItem.Text);