我所做的所有研究似乎都表明,如果我再次調用DataBind(),那麼我的GridView將會更新。這似乎只是如果我正在調試和逐步通過我的代碼,gridview刷新罰款。但是,如果我在調試模式下運行應用程序時沒有瀏覽代碼,則下面的btnFileImport_Click方法不會刷新我的gridview。這與我通過使用SSIS包加載文件來更新gridview使用的數據有什麼關係?下面是代碼隱藏:即使再次調用數據綁定,頁面上的gridview也不會刷新
namespace InternationalWires
{
public partial class Default_Corporate : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InternationalWiresConnection"].ToString());
SqlCommand cmd = null;
SqlServerAgent sqlAgent = new SqlServerAgent();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRatesGrid();
}
}
public void BindRatesGrid()
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InternationalWiresConnection"].ToString());
SqlDataAdapter da = new SqlDataAdapter("spGetRates", conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
da.Fill(ds);
grdRates.DataSource = ds.Tables[0].DefaultView;
grdRates.DataBind();
}
protected void btnFileImport_Click(object sender, EventArgs e)
{
// Get the filename and path from the user. Must be in UNC format or SSIS will fail
string filename = Path.GetFullPath(fileSelect.PostedFile.FileName);
// Update the settings table to the value from above
try
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InternationalWiresConnection"].ToString());
cmd = new SqlCommand("UPDATE Settings SET settingValue = '" + filename + "' WHERE settingName = 'SSISRatesImportFile'", conn);
conn.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
// TO DO: handle exceptions
}
finally
{
if (conn != null) conn.Dispose();
if (cmd != null) cmd.Dispose();
}
// set the name of the ssis package to run
sqlAgent.SSISName = ConfigurationManager.AppSettings["ratesImportPackage"].ToString();
// start the job
sqlAgent.SQL_SSISPackage();
// do nothing while waiting for job to finish
while (sqlAgent.SQL_IsJobRunning())
{ }
if (sqlAgent.SQL_JobSucceeded())
{
lblStatus.Text = "Import Succeeded";
BindRatesGrid();
}
else
{
lblStatus.Text = "Import Failed. Please contact IT for failure details on SSIS import package.";
}
}
}
}
我假設你'// TO DO:處理exceptions'就是爲什麼當我通過它從來沒有碰到異常的代碼步驟GridView控件沒有更新;-) – 2012-02-08 19:37:45
的原因,所以我不知道爲什麼會這樣。 – BeachBum 2012-02-08 20:54:58
在該部分添加一些代碼沒有任何區別。 – BeachBum 2012-02-08 21:05:23