gpt4 book ai didi

c# - 页面上的 GridView 不会刷新,即使再次调用 DataBind

转载 作者:太空宇宙 更新时间:2023-11-03 16:35:35 24 4
gpt4 key购买 nike

我所做的所有研究似乎表明,如果我再次调用 DataBind(),我的 GridView 就会更新。这似乎只有在我调试和单步执行我的代码时才会出现这种情况,GridView 刷新良好。但是,如果我在 Debug模式下运行应用程序时没有单步执行我的代码,下面的 btnFileImport_Click 方法不会刷新我的 GridView。这与我更新 GridView 通过使用 SSIS 包加载文件所使用的数据有什么关系吗?下面是背后的代码:

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

}
}
}

最佳答案

我建议将您的网格放入更新面板。看起来当您单击按钮时,页面不会在回传中刷新,因此网格不会...

关于c# - 页面上的 GridView 不会刷新,即使再次调用 DataBind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9200048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com