symon
symon

Reputation: 13

Transfer data to another table and make previous GridView empty

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
            {

            }
        }

        }
    }

Upvotes: 0

Views: 545

Answers (2)

Habib
Habib

Reputation: 223247

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();
   }

Upvotes: 1

Mike B
Mike B

Reputation: 5451

Are you clearing the previous gridview anywhere? Maybe try this before your redirect:

grvPrevious.DataSource = null;
grvPrevious.DataBind();

Upvotes: 1

Related Questions