下面是MakeDataSource()和他唯一调用的子函数,是在MSDN的例子基础上改的,连注释都没去掉:private DataTable MakeDataSource()
{
// Use the MakeTable function below to create a new table.
DataTable myTable;
myTable = MakeNamesTable();
// Once a table has been created, use the NewRow to create a DataRow.
DataRow myRow;
Mark = new Mark();
InfoManager im = new InfoManager();
ArrayList allemplist = im.GetAllEmp();
for(int i = 0; i < allemplist.Count; i++)
{
myRow = myTable.NewRow();
// Then add the new row to the collection.
string empid = allemplist[i].ToString();
myRow["ID"] = empid;
myRow["Name"] = im.GetEmpName(empid);
myRow["Depart"] = im.GetDepartName(im.GetDepartIDFromEmpID(empid));
if(im.IsMaster(empid))
myRow["Master"] = "<font color=red>是</font>";
else
myRow["Master"] = "否";
myTable.Rows.Add(myRow);
}
return myTable;
}private DataTable MakeNamesTable()
{
// Create a new DataTable titled 'Names.'
DataTable namesTable = new DataTable("empList");
// Add three column objects to the table.
DataColumn idColumn = new DataColumn();
idColumn.DataType = System.Type.GetType("System.String");
idColumn.ColumnName = "ID";
namesTable.Columns.Add(idColumn); DataColumn NameColumn = new DataColumn();
NameColumn.DataType = System.Type.GetType("System.String");
NameColumn.ColumnName = "Name";
namesTable.Columns.Add(NameColumn);
DataColumn DepartColumn = new DataColumn();
DepartColumn.DataType = System.Type.GetType("System.String");
DepartColumn.ColumnName = "Depart";
namesTable.Columns.Add(DepartColumn); DataColumn masterColumn = new DataColumn();
masterColumn.DataType = System.Type.GetType("System.String");
masterColumn.ColumnName = "Master";
namesTable.Columns.Add(masterColumn); return namesTable;
}
{
// Use the MakeTable function below to create a new table.
DataTable myTable;
myTable = MakeNamesTable();
// Once a table has been created, use the NewRow to create a DataRow.
DataRow myRow;
Mark = new Mark();
InfoManager im = new InfoManager();
ArrayList allemplist = im.GetAllEmp();
for(int i = 0; i < allemplist.Count; i++)
{
myRow = myTable.NewRow();
// Then add the new row to the collection.
string empid = allemplist[i].ToString();
myRow["ID"] = empid;
myRow["Name"] = im.GetEmpName(empid);
myRow["Depart"] = im.GetDepartName(im.GetDepartIDFromEmpID(empid));
if(im.IsMaster(empid))
myRow["Master"] = "<font color=red>是</font>";
else
myRow["Master"] = "否";
myTable.Rows.Add(myRow);
}
return myTable;
}private DataTable MakeNamesTable()
{
// Create a new DataTable titled 'Names.'
DataTable namesTable = new DataTable("empList");
// Add three column objects to the table.
DataColumn idColumn = new DataColumn();
idColumn.DataType = System.Type.GetType("System.String");
idColumn.ColumnName = "ID";
namesTable.Columns.Add(idColumn); DataColumn NameColumn = new DataColumn();
NameColumn.DataType = System.Type.GetType("System.String");
NameColumn.ColumnName = "Name";
namesTable.Columns.Add(NameColumn);
DataColumn DepartColumn = new DataColumn();
DepartColumn.DataType = System.Type.GetType("System.String");
DepartColumn.ColumnName = "Depart";
namesTable.Columns.Add(DepartColumn); DataColumn masterColumn = new DataColumn();
masterColumn.DataType = System.Type.GetType("System.String");
masterColumn.ColumnName = "Master";
namesTable.Columns.Add(masterColumn); return namesTable;
}
我忘了在那里設了﹐你自己找找看啊﹐應該不是.NET的BUG﹐我有用SESSION
來保存值啊﹐好像沒有這個問題呢
肯定是程序的BUG
一这样写绝对会丢session!!