protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            string regno = (string)Session["ID"];
            regno = regno.Replace(" ", String.Empty).ToString();
            Response.Write("Register Number:" + regno);
            string cid = DropDownList1.SelectedValue;
            cid = cid.Replace(" ", String.Empty).ToString();;
            // var flag = "f";
            var ans = "no";
            DataClassesDataContext cx3 = new DataClassesDataContext();
            var result = cx3.ExecuteQuery <detailCompany>("Select * from detailCompany where companyid={0}", cid);
            foreach (var r in result)
            {
                //Response.Write("true");
                using (DataClassesDataContext cx4 = new DataClassesDataContext())
                {
                    var query = cx4.ExecuteQuery <StudentsJobApplied>("Select * from StudentsJobApplied where studentid={0}", regno);
                    foreach (var s in query)
                    {
                        //  Response.Write("Company ID: "+s.companyid+" "+cid+" Student ID: "+s.studentid+" "+regno);
                        if (s.companyid.Contains(cid))
                        {
                            if (s.studentid.Contains(regno))
                            {
                                lbstatus.Text = "You have Already Registered!";
                                ans           = "yes";
                            }
                        }
                    }
                    if (ans == "no")
                    {
                        StudentsJobApplied job_reg = new StudentsJobApplied
                        {
                            companyid = DropDownList1.SelectedValue,
                            studentid = regno,
                        };
                        cx4.StudentsJobApplieds.InsertOnSubmit(job_reg);
                        cx4.SubmitChanges();
                        lbstatus.Text = "Successfully Applied";
                        //flag = "t";
                    }
                }
            }

            /*  if(flag!="t")
             * {
             *    //Response.Write("false");
             *    lbstatus.Text = "Invalid - Company ID Does not exists";
             * }*/
        }
    }
 partial void DeleteStudentsJobApplied(StudentsJobApplied instance);
 partial void UpdateStudentsJobApplied(StudentsJobApplied instance);
 partial void InsertStudentsJobApplied(StudentsJobApplied instance);