CODE BEHIND
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!Page.IsPostBack)
{
ViewState["StudentList"] = GetStudentList();
BindGrid();
}
}
}
protected void BindGrid()
{
Studentlist.DataSource = ViewState["StudentList"];
Studentlist.DataBind();
}
static DataTable GetStudentList()
{
//I Have Created Virtual table
DataTable table = new DataTable();
table.Columns.Add("StudentName", typeof(string));
table.Columns.Add("Address", typeof(string));
table.Columns.Add("Phone", typeof(string));
table.Columns.Add("JoingDate", typeof(DateTime));
// Now have created some row to fill the the datatable
table.Rows.Add( "Samim", "Dhaka","01856587548", "11/5/2007");
table.Rows.Add("Ahsan", "Chittagong", "01856587548","12/ 5/2007");
table.Rows.Add("Nirub", "Sylhet", "01856587544", "11/10/ 2007");
table.Rows.Add("Zaman", "Rajsahi", "01856587578", "11 /15/ 2007");
table.Rows.Add("Habib", "Barisal", "01856587548", "11 /5 / 2010");
table.Rows.Add("Roman", "Chandpur", "01856587548", "11 /5 / 2010");
table.Rows.Add("Iqbal Hossain", "Noakhali", "01856587548", "11 /5 / 2010");
return table;
}
protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
DataTable dt = ViewState["StudentList"] as DataTable;
dt.Rows[index].Delete();
ViewState["dt"] = dt;
BindGrid();
}