Guest User

Guest User

  • Tech Writer
  • 189
  • 25k

My student list not comming

Aug 17 2018 7:43 AM
  1. //INDEX  
  2.   
  3. <script src="~/scripts/jquery-1.10.2.min.js"></script>  
  4. <script src="~/scripts/bootstrap.min.js"></script>  
  5. <link href="~/Content/bootstrap.min.css" rel="stylesheet" />  
  6. <div class="container" style="margin-top :4%">  
  7.     <a href="#" class="btn btn-info" onclick="AddnewStudent(0)"> Add New Student</a>  
  8.     <table class="table table-striped">  
  9.         <thead>  
  10.             <tr>  
  11.                 <th>Student Name</th>  
  12.                 <th>Email ID</th>  
  13.                 <th>Department</th>  
  14.                 <th>Edit</th>  
  15.                 <th>Delete</th>  
  16.             </tr>  
  17.         </thead>  
  18.         <tbody id="SetStudentList">  
  19.             <tr id="LoadingStatus" style="color:red"></tr>  
  20.         </tbody>  
  21.     </table>  
  22. </div>  
  1. //javascript  
  2.  $('#LoadingStatus').html("Loading....")  
  3.     //$.get("@Url.Action("GetStudentList","Home")", null, DataBind);  
  4.     $.ajax({  
  5.         type: 'Get',  
  6.         url: "@Url.Action("GetStudentList", "Home")",  
  7.         datatype: 'json',  
  8.         success: function DataBind(StudentList) {  
  9.             var SetData = $('#SetStudentList');  
  10.             for (var i = 0; i < StudentList.length; i++) {  
  11.                 var Data = "<tr class='row_" + StudentList[i].studentID + "'>" +  
  12.                     "<td>" + StudentList[i].studentName + "</td>" +  
  13.                     "<td>" + StudentList[i].email + "</td>" +  
  14.                     "<td>" + StudentList[i].DepartmentName + "</td>" +  
  15.                     "<td>" + "<a href='#' class='btn btn-warning' onclick='EditStudentRecord(" + StudentList[i].studentID + ")' ><span class='glyphicon glyphicon-edit'></span></a>" + "</td>" +  
  16.                     "<td>" + "<a href='#' class='btn btn-danger' onclick='DeleteStudentRecord(" + StudentList[i].studentID + ")'><span class='glyphicon glyphicon-trash'></span></a>" + "</td>" +  
  17.                     "</tr>";  
  18.                 SetData.append(Data);  
  19.                 //  $("#LoadingStatus").html(" ");  
  20.             }  
  21.         },  
  22.         error: function (DataBind) {  
  23.             alert(DataBind.message);  
  24.         }  
  25.     })  
  1.  public List<StudentDetails> GetStudData()  
  2.         {  
  3.             connection();  
  4.             List<StudentDetails> students = new List<StudentDetails>();  
  5.             string Sqry = "select st.StudentID,st.StudentName,st.Email, st.isDelete,st.Department_ID,dt.Department_Name from tbl_Student st "  
  6.                 + "inner join tbl_Department dt on dt.Department_ID = st.Department_ID";  
  7.             SqlCommand cmd = new SqlCommand(Sqry,con);  
  8.             cmd.CommandType = CommandType.Text;  
  9.             SqlDataAdapter sdr = new SqlDataAdapter(cmd);  
  10.             DataTable dt = new DataTable();  
  11.             con.Open();  
  12.             sdr.Fill(dt);  
  13.             con.Close();  
  14.             foreach(DataRow dr in dt.Rows)  
  15.             {  
  16.                 students.Add(  
  17.                     new StudentDetails  
  18.                     {  
  19.                         studentID = Convert.ToInt32(dr["StudentID"]),  
  20.                         studentName =Convert.ToString(dr["StudentName"]),  
  21.                         email = Convert.ToString(dr["Email"]),  
  22.                         IsDeleted = Convert.ToBoolean(dr["isDelete"]),  
  23.                         DepartmentId = Convert.ToInt32(dr["Department_ID"]),  
  24.                         DepartmentName = Convert.ToString(dr["Department_Name"]),  
  25.                     });  
  26.             }  
  27.             return students;  
  28.         }  
  29.   
  30. public JsonResult GetStudentList()  
  31.         {  
  32.           
  33.             StudentDetails stud = new StudentDetails();  
  34.             var students = stud.GetStudData();  
  35.             return Json(new { data = students }, JsonRequestBehavior.AllowGet);  
  36.         }  

Answers (2)