using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class BindDataDataList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LoadAllStudent();
}
private void LoadAllStudent()
{
List<Student> list = new List<Student>();
list.Add(new Student("Samim", 39, "Dhaka"));
list.Add(new Student("Asad", 48, "Chittagong"));
list.Add(new Student("Nayed", 39, "Sylhet"));
list.Add(new Student("Anwar", 48, "Dhaka"));
lstStudentlist.DataSource = list;
lstStudentlist.DataBind();
}
public class Student
{
public Student(string StudentName, int StudentAge, string Address)
{
_StudentName = StudentName;
_StudentAge = StudentAge;
_Address = Address;
}
private string _Address;
public string Address
{
get { return _Address; }
set { _Address = value; }
}
private int _StudentAge;
public int StudentAge
{
get { return _StudentAge; }
set { _StudentAge = value; }
}
private string _StudentName;
public string StudentName
{
get { return _StudentName; }
set { _StudentName = value; }
}
}
protected void lstStudentlist_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Student entry = e.Item.DataItem as Student;
HyperLink lnkName = e.Item.FindControl("lnkName") as HyperLink;
lnkName.Text = entry.StudentName.ToString();
Label lblAddress = e.Item.FindControl("lblAddress") as Label;
lblAddress.Text = entry.Address;
Label lblAge = e.Item.FindControl("lblAge") as Label;
lblAge.Text = entry.StudentAge.ToString();
}
}
}