public List <tblGuardian> LoadGuardian() { List <tblGuardian> cboList = null; tblGuardian item = new tblGuardian(); item.GuardianId = 0; item.guardName = "Select"; try { cboList = dbcontext.tblGuardians.OrderBy(c => c.guardName).ToList(); } catch { } cboList.Insert(0, item); return(cboList); }
protected void Button_Click_Guardian_Register(object sender, EventArgs e) { try { tblGuardian item = new tblGuardian(); item.StudentId = int.Parse(drpStudentId.SelectedValue); item.StudentId2 = int.Parse(drpStudentId2.SelectedValue); item.StudentId3 = int.Parse(drpStudentId3.SelectedValue); item.StudentId4 = int.Parse(drpStudentId4.SelectedValue); item.StudentId5 = int.Parse(drpStudentId5.SelectedValue); item.guardName = txtGuardianName.Text.ToString(); // item.guardAddress = txtGuardianAddress.Text.ToString(); item.guardPhone = txtGuardianContactNo.Text.Trim(); item.guardEmail = txtGuardianEmail.Text.ToString(); dbcontext.tblGuardians.AddObject(item); tblUserLoginInfo item1 = new tblUserLoginInfo(); item1.userName = txtUserNameStudent.Text.Trim(); item1.userPassword = txtPasswordStudent.Text.Trim(); item1.userRole = "Guardian"; item1.GuardianId = (int)item.GuardianId; dbcontext.tblUserLoginInfoes.AddObject(item1); dbcontext.SaveChanges(); for (int i = 2; i <= 5; i++) { var container = Master.FindControl("ContentPlaceHolder1"); string rayhan = "drpStudentId" + i; DropDownList lbl = (DropDownList)container.FindControl(rayhan); } string script = "alert('User Saved');"; ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true); } catch { string script = "alert('Duplicate items are Not Allowed');"; ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true); } }