将数据传输到另一个表,使previous GridView的空 [英] Transfer data to another table and make previous GridView empty
问题描述
我 GridView控件
。当我点击一个按钮,它发送数据到另一个表,使previous GridView控件
空。
我有以下的code的按钮点击,但它不会使previous GridView控件
空。
保护无效的button1_Click(对象发件人,EventArgs的发送)
{
康涅狄格州的SqlConnection =新的SqlConnection(ConfigurationManager.ConnectionStrings [的ConnectionString]的ConnectionString);
conn.Open();
字符串userApply =插入到公司(公司名称)选择(JOBTITLE)从乔布斯那里JOBTITLE = JOBTITLE;
的SqlCommand insertApply =新的SqlCommand(userApply,康涅狄格州); 尝试
{
insertApply.ExecuteNonQuery();
conn.Close();
的Response.Redirect(ApplyJob.aspx);
}
赶上(例外ER)
{
的Response.Write(er.ToString());
}
最后
{ }
} }
}
它看起来像你在ApplyJob.aspx你的GridView,因为要重定向到该网页在try块有你看到的GridView持有约值。你可以通过一个查询字符串ApplyJob.aspx一起,然后在ApplyJob.aspx的表单负荷检查该查询字符串。如果您发现该值,则清除GridView控件。东西以下行..
在你的try块做的:
的Response.Redirect(?ApplyJob.aspx ClearGridView = YES);
在ApplyJob.aspx检查查询字符串的Form_Load事件
如果(的Request.QueryString [ClearGridView] = NULL&放大器;!&放大器;的Request.QueryString [ClearGridView] ==是)
{
yourGridView.DataSource = NULL;
youGridView.DataBind();
}
I have GridView
. When I click a button, it sends data to another table and makes the previous GridView
empty.
I have the following code for the button click, but it does not make the previous GridView
empty.
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string userApply = "insert into Company (CompanyName) select (JobTitle) from Jobs where JobTitle=JobTitle";
SqlCommand insertApply = new SqlCommand(userApply, conn);
try
{
insertApply.ExecuteNonQuery();
conn.Close();
Response.Redirect("ApplyJob.aspx");
}
catch (Exception er)
{
Response.Write(er.ToString());
}
finally
{
}
}
}
}
it looks like you have your GridView in ApplyJob.aspx, since you are redirecting to that page in your try block and there you see the gridview holding some values. You may pass a query string along with ApplyJob.aspx and then in your form load of ApplyJob.aspx check for that query string. If you find the value then clear the Gridview. Something on the following line.. In your try block do :
Response.Redirect("ApplyJob.aspx?ClearGridView=YES");
In your Form_Load event of the ApplyJob.aspx check for the query string
if(Request.QueryString["ClearGridView"] != null && Request.QueryString["ClearGridView"] =="YES")
{
yourGridView.DataSource = null;
youGridView.DataBind();
}
这篇关于将数据传输到另一个表,使previous GridView的空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!