protected void Page_Load(object sender, EventArgs e) { StudentManager aStudentManager = new StudentManager(); StudentGridView.DataSource = aStudentManager.GetAllStudents(); StudentGridView.DataBind(); }
protected void Add_Click(object sender, EventArgs e) { if (Page.IsValid) { bool found = false; foreach (var item in Students) { if (item.StudentID == int.Parse(StudentID.Text)) { found = true; } } if (found) { MessageLabel.Text = "Record already exists."; } else { Student newStudent = new Student(int.Parse(StudentID.Text), Name.Text, double.Parse(Credits.Text), Phone.Text); Students.Add(newStudent); StudentGridView.DataSource = Students; StudentGridView.DataBind(); } } }
/// <summary> /// This method gets the Students data from the DB /// </summary> private void GetStudentsDetails() { int StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); // Connect to Entity FrameWork using (ControlsoContext db = new ControlsoContext()) { //Query the Students Table using EF and LINQ var Students = (from allStudents in db.Students where allStudents.StudentID == StudentID select allStudents); // bind the result to the Student GridView StudentGridView.DataSource = Students.ToList(); StudentGridView.DataBind(); //Query the Course Table using EF and LINQ var CoursesDetails = (from allCourse in db.Courses join enrolment in db.Enrollments on allCourse.CourseID equals enrolment.CourseID where enrolment.StudentID == StudentID select new { CourseID = allCourse.CourseID, Title = allCourse.Title, Grade = enrolment.Grade, Credit = allCourse.Credits }); // bind the result to the Course GridView StudentCourseView.DataSource = CoursesDetails.ToList(); StudentCourseView.DataBind(); } }
private void bindStudentGridView(string name) { StudentGridView.DataSource = getStudentData(name); StudentGridView.DataKeyNames = new string[] { "Sno" };//主键 StudentGridView.DataBind(); sqlcon.Close(); }
private void GetDataFromCache() { if (Cache["DATASET"] != null) { DataSet ds = (DataSet)Cache["DATASET"]; StudentGridView.DataSource = ds; StudentGridView.DataBind(); } }
private void getStudents() { using (ContosoContext db = new ContosoContext()) { var students = (from allstudents in db.Students select allstudents); StudentGridView.DataSource = students.ToList(); StudentGridView.DataBind(); } }
public void GetAllStudentByClass() { try { string name = ClassDropDownList.SelectedItem.ToString(); StudentGridView.DataSource = _StudentRepository.GetAllStudentByClass(name); StudentGridView.DataBind(); } catch { } }
protected void ClassDropDownList_SelectedIndexChanged(object sender, EventArgs e) { try { IdHiddenField.Value = ClassDropDownList.SelectedItem.ToString(); string name = ClassDropDownList.SelectedItem.ToString(); StudentGridView.DataSource = _StudentRepository.GetAllStudentByClass(name); StudentGridView.DataBind(); } catch { } }
protected void ClassDropDownList_SelectedIndexChanged(object sender, EventArgs e) { try { string name = ClassDropDownList.SelectedItem.ToString(); StudentGridView.DataSource = _StudentRepository.GetAllStudentByClass(name); StudentGridView.DataBind(); ChangeButton.Visible = true; } catch { } }
/// <summary> /// This method gets the Students data from the DB /// </summary> private void GetStudents() { // Connect to Entity FrameWork using (ControlsoContext db = new ControlsoContext()) { //Query the Students Table using EF and LINQ var Students = (from allStudents in db.Students select allStudents); // bind the result to the Student GridView StudentGridView.DataSource = Students.ToList(); StudentGridView.DataBind(); } }
private void getStudents() { //connect to Entity Framework Database using (ContosoContext db = new ContosoContext()) { //query the student data var studnets = (from allStudents in db.Students select allStudents); // bind the resultset to the student grid StudentGridView.DataSource = studnets.ToList(); StudentGridView.DataBind(); } }
protected void FetchStudents() { string sortString = Session["SortColumn"] + " " + Session["SortDirection"]; using (DefaultConnection db = new DefaultConnection()) { // query the student's table using EF and LINQ var student = (from studentList in db.Students select studentList); // bind the result to the grid view // StudentGridView.DataSource = student.ToList(); StudentGridView.DataSource = student.AsQueryable().OrderBy(sortString).ToList(); StudentGridView.DataBind(); } }
private void LoadStudentGrid() { StudentGridView.DataSource = OgrenciDAO.GetData(LoggedAcademician.Id); StudentTable = StudentGridView.DataSource as DataTable; for (int i = 4; i < StudentGridView.ColumnCount; i++) { StudentGridView.Columns[i].ReadOnly = true; } for (int i = 0; i < StudentGridView.ColumnCount; i++) { StudentGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } StudentGridView.AutoResizeColumns(); }
private void GetDataFromDB() { string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; SqlConnection con = new SqlConnection(CS); string strSelectQuery = "Select * from tblStudent"; SqlDataAdapter da = new SqlDataAdapter(strSelectQuery, con); DataSet ds = new DataSet(); da.Fill(ds, "Students"); ds.Tables["Students"].PrimaryKey = new DataColumn[] { ds.Tables["Students"].Columns["ID"] }; Cache.Insert("DATASET", ds, null, DateTime.Now.AddHours(24), System.Web.Caching.Cache.NoSlidingExpiration); StudentGridView.DataSource = ds; StudentGridView.DataBind(); lblMessage.Text = "Data loaded from Database"; }
private void TraziBtn_Click(object sender, EventArgs e) { string parametar = searchNameInput.Text.Trim() + '/' + GradCmb.SelectedValue.ToString(); if (String.IsNullOrEmpty(searchNameInput.Text)) { parametar = "Empty" + '/' + GradCmb.SelectedValue.ToString(); } var response = studentService.GetActionResponse("SearchStudent", parametar); if (response.IsSuccessStatusCode) { var lstStudent = response.Content.ReadAsAsync <List <Student_SearchSelect_Result> >().Result; StudentGridView.DataSource = lstStudent; StudentGridView.ClearSelection(); } ; }
private void addToolStripMenuItem_Click(object sender, EventArgs e) { addToolStripMenuItem.Enabled = false; exitAddToolStripMenuItem.Enabled = true; this.Height = 600; StudentGridView.Hide(); SearchButton.Hide(); StudentSearctBox.Hide(); label10.Hide(); StudentAddForm.Show(); StudentDeleteButton.Hide(); label11.Hide(); label12.Hide(); FirstPageButton.Hide(); NextPageButton.Hide(); PreviousButton.Hide(); LastPageButton.Hide(); RefreshButton.Hide(); }
private void ShowAllStudentInfo() { List <Student> studentList = new List <Student>(); string connectionString = @"Server = RDFOX; Database = StudentInfoDB; Integrated Security = true;"; SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM Student_tbl ORDER BY StudentID DESC"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int studentId = (int)reader["StudentId"]; string studentName = reader["StudentName"].ToString(); string regNo = reader["RegNo"].ToString(); string email = reader["Email"].ToString(); string mobileNo = reader["MobileNo"].ToString(); int age = (int)reader["Age"]; string address = reader["Address"].ToString(); Student student = new Student(studentName, regNo, email, mobileNo, age, address); student.StudentId = studentId; studentList.Add(student); } reader.Close(); connection.Close(); StudentGridView.DataSource = studentList; StudentGridView.DataBind(); }
protected void SubmitBtn_Click(object sender, EventArgs e) { using (SchoolDBContext db = new SchoolDBContext()) { if (byId_rdb.Checked) { try { int id = Int32.Parse(QueryBox.Text); var std = db.Students.Find(id); DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add("ID"); dt.Columns.Add("First Name"); dt.Columns.Add("Last Name"); DataRow dr = dt.NewRow(); dr[0] = std.Id; dr[1] = std.FirstName; dr[2] = std.LastName; dt.Rows.Add(dr); StudentGridView.DataSource = dt; StudentGridView.DataBind(); } catch (NullReferenceException) { lblExceptionsMsg.Text = "Invalid ID entered. Please re-enter a valid ID"; } catch (Exception ex) { lblExceptionsMsg.Text = "Unknown Error, Please re-submit your inquiry. Exception Message : " + ex.Message; } } else if (byFname_rdb.Checked) { try { string firstName = QueryBox.Text; var studentList = db.Students.Where(s => s.FirstName.Contains(firstName)).ToList(); DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add("ID"); dt.Columns.Add("First Name"); dt.Columns.Add("Last Name"); foreach (Student std in studentList) { DataRow dr = dt.NewRow(); dr[0] = std.Id; dr[1] = std.FirstName; dr[2] = std.LastName; dt.Rows.Add(dr); } StudentGridView.DataSource = dt; StudentGridView.DataBind(); } catch (NullReferenceException) { lblExceptionsMsg.Text = "Invalid Name entered. Please re-enter a valid Name"; } catch (Exception ex) { lblExceptionsMsg.Text = "Unknown Error, Please re-submit your inquiry. Exception Message : " + ex.Message; } } else if (byLname_rdb.Checked) { try { string lastName = QueryBox.Text; var studentList = db.Students.Where(s => s.LastName.Contains(lastName)).ToList(); DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add("ID"); dt.Columns.Add("First Name"); dt.Columns.Add("Last Name"); foreach (Student std in studentList) { DataRow dr = dt.NewRow(); dr[0] = std.Id; dr[1] = std.FirstName; dr[2] = std.LastName; dt.Rows.Add(dr); } StudentGridView.DataSource = dt; StudentGridView.DataBind(); } catch (NullReferenceException) { lblExceptionsMsg.Text = "Invalid Name entered. Please re-enter a valid Name"; } catch (Exception ex) { lblExceptionsMsg.Text = "Unknown Error, Please re-submit your inquiry. Exception Message : " + ex.Message; } } } }
public void GetAllStudents() { StudentGridView.DataSource = _StudentRepository.GetAllStudent(); StudentGridView.DataBind(); }