I want to sort my data which are bound to the dropdown.
I fetch the name of students from database but thought i can’t directly use the orderby.
Because the data i get from the database is student id which is of Guid type.
Then i am finding the full name from the id.
Here’s the code
public DataTable GetAllStudentNameFromMentor(Guid MentorId)
{
DataTable AllStudents = new DataTable();
AllStudents.Columns.Add("StudentID", typeof(Guid));
AllStudents.Columns.Add("studentName", typeof(string));
var allm = from sm in Db.StudentMentor
where sm.MentorID.Equals(MentorId)
select sm;
foreach (var v in allm)
{
string studentname = BussinesCollection.BussinesPerson.GetFullName(v.StudentID.Value);
AllStudents.Rows.Add(v.StudentID,studentname);
}
return AllStudents;
}
I am binding the table in dropdown.
ddlstudent.DataSource = m.bussinesCollection.BussinesMentor.GetAllStudentNameFromMentor(MentorID);
ddlstudent.DataBind();
But I want the names should be in alphabetical order.
Would anyone like to help me..
We can sort datatable using dataview as below :