*******************Singel Item Binding********************
public class Student
{
public int StudentId { get; set; }
[Display(Name = "Name")]
public string StudentName { get; set; }
public int Age { get; set; }
public Standard standard { get; set; }
}
public class Standard
{
public int StandardId { get; set; }
public string StandardName { get; set; }
}
bind to class
Student s = new Student();
s.Age = 25;
s.standard.StandardId = 25;
s.standard.StandardName = "New Sand";
s.StudentId=2;
s.StudentName = "Samir";
***********************************
*******************List of Item Binding********************
public class Student
{
public int StudentId { get; set; }
[Display(Name = "Name")]
public string StudentName { get; set; }
public int Age { get; set; }
public List<Standard> listStad { get; set; }
}
public class Standard
{
public int StandardId { get; set; }
public string StandardName { get; set; }
}
bind to class
Student s = new Student();
s.Age = 25;
s.listStad =
new List<Standard>() {
new Standard { StandardId = 25, StandardName = "Samir" },
new Standard { StandardId = 26, StandardName = "samir 02" }
};
s.StudentId=2;
s.StudentName = "Samir";
******************************************************
Bind data By Datatable
public class Group
{
public string name { get; set; }
public string id { get; set; }
public bool expanded { get; set; }
public List<Resoruce> children { get; set; }
}
public class Resoruce
{
public string name { get; set; }
public string id { get; set; }
public string groupid { get; set; }
}
public ActionResult ShowData()
{
dal.ClearParameters();
dal.AddParameter("@MODE", "SELECT_GROUP", "IN");
DataTable dtgroup = dal.GetTable("SP_EVENTS", ref Message);
dal.ClearParameters();
dal.AddParameter("@MODE", "SELECT_SCHE_GROUP_MEMBER_SHOW", "IN");
DataTable dtres = dal.GetTable("SP_EVENTS", ref Message);
List<Group> groups = new List<Group>();
for (int i = 0; i < dtgroup.Rows.Count; i++)
{
Group group = new Group
{
id = dtgroup.Rows[i]["ID"].ToString(),
name = dtgroup.Rows[i]["name"].ToString(),
expanded = true,
children = getResoruce(dtgroup.Rows[i]["groupId"].ToString(), dtres)
};
groups.Add(group);
}
ViewBag.Datax = groups;
return View();
}
public List<Resoruce> getResoruce(string groupId, DataTable resours)
{
DataRow[] result = resours.Select("groupId='" + groupId + "'");
List<Resoruce> detail = new List<Resoruce>();
foreach (var item in result)
{
detail.Add(new Resoruce
{
groupid = item["groupId"].ToString(),
id = item["id"].ToString(),
name = item["name"].ToString()
});
}
return detail;
}