Gridview checkbox checked inserts only the last selected value
<p>I'm trying to do a fileupload based on checkbox checked values(optional) based on my code but still i get only my last checkboxselected value inserted.What i exactly need is if checkbox item checked then I insert selected item values along with form data otherwise i insert the form datas.Also,I've created Insert stored procedure which handles multiple tables and bridge table insertion.</p>

<p>Any Help.please..My code is as follows  </p>

<pre><code>string filepath = "~/"+"Uploads/" + Path.GetFileName(FileUpload1.PostedFile.FileName);
string filename = Path.GetFileName(filepath);
string strcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
if (FileUpload1.HasFile)
{
    string Viewname = string.Empty;
    using (SqlConnection scn = new SqlConnection(strcon))
    {

        foreach (GridViewRow gvrow in GridView1.Rows)
        {
            CheckBox check_box = (CheckBox)gvrow.FindControl("checkbox1");
            if (check_box != null)
            {
                if (check_box.Checked)
                {

                    viewname = Convert.ToString(gvrow.Cells[1].Text);
                }

                else
                    using (SqlCommand csm = scn.CreateCommand())
                    {
                        scn.Open();
                        SqlCommand cmd = new SqlCommand("Insert", scn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = TextBox1.Text;

                        cmd.Parameters.Add("@View", SqlDbType.NVarChar).Value = Viewname;
                        //conn.Open();
                        cmd.ExecuteNonQuery();
                        scn.Close();
                        FileUpload1.SaveAs(Server.MapPath(filepath));
                        Label8.Text = "FileSuccessfully Uploaded !";



                    }

            }
        }
    }
}
</code></pre>
