using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
///
/// Summary description for ProfileList.
/// Technilogies used: ListBox, DataGrid, Session, ArrayList. DataTable
///
public class ProfileList : Page
{
public Label debugMessage;
public DataGrid matchedList;
public ListBox RoleList, ProgramList;
DataTable tableValues;
public ProfileList()
{
//
// TODO: Add constructor logic here
//
}
public void Page_Load(Object Src, EventArgs E)
{
if(!IsPostBack)
{
matchedList.DataSource = GetDataView("");
matchedList.DataBind();
}
}
DataTable GetDataTable()
{
tableValues = (DataTable)Session["tableValues"];
if(tableValues != null)
return tableValues;
else
return null;
}
void AddToTable(string role, string program)
{
DataTable data = GetDataTable();
if(data == null)
{
//first time, no data in the data table
data = new DataTable();
DataColumn prim = data.Columns.Add("EmpNo", typeof(int));
prim.AutoIncrement=true;
prim.AutoIncrementSeed=1;
prim.AutoIncrementStep=2;
data.Columns.Add("FirstNme", typeof(string));
data.Columns.Add("LastName", typeof(string));
data.PrimaryKey = new DataColumn[] {data.Columns["EmpNo"]}; //Need set primary key for Find later
}
DataRow dr;
dr = data.NewRow();
dr[1] = role;
dr[2] = program;
data.Rows.Add(dr);
Session["tableValues"] = data;
matchedList.DataSource = GetDataView("");
matchedList.DataBind();
//debugMessage.Text = debugMessage.Text + " " + role+program;
}
DataView GetDataView(string sortString)
{
if(GetDataTable() == null)
return null;
DataView view = new DataView(GetDataTable());
view.Sort = sortString; //problem: sort lost in new pages
return view;
}
public void SortDataGrid(object o, DataGridSortCommandEventArgs e)
{
matchedList.DataSource = GetDataView(e.SortExpression);
matchedList.DataBind();
}
public void PageChange(object sender, DataGridPageChangedEventArgs e)
{
matchedList.CurrentPageIndex = e.NewPageIndex;
matchedList.DataSource = GetDataView("");
matchedList.DataBind();
}
public void OnClickBtn_Add(object sender, EventArgs e)
{
string new_role="";
string new_program="";
//two kind of for loops
for (int i=0; icheckbox found " + item.Cells[3].UniqueID ;
//debugMessage.Text += "
checkbox status is " + selection.Checked;
if (selection.Checked) //remove table row
{
//debugMessage.Text += "
delete Item is - " + item.Cells[1].Text ;
DataRow rmRow = data.Rows.Find(item.Cells[0].Text);
deletedRowList.Add(rmRow);
//debugMessage.Text += "remove row "+ rmRow["EmpNo"];
}
}
}
foreach(DataRow rmRow in deletedRowList)
{
data.Rows.Remove(rmRow);
}
Session["tableValues"] = data;
matchedList.DataSource = GetDataView("");
matchedList.CurrentPageIndex=0;
matchedList.DataBind();
}
}