protected void Semester_DDL_SelectedIndexChanged(object sender, EventArgs e) { //定義Details_DataTable及內部資料行(要有那些欄位) DataTable Details_DataTable = new DataTable(); Details_DataTable.Columns.Add("ID"); Details_DataTable.Columns.Add("Name"); Details_DataTable.Columns.Add("Department"); Details_DataTable.Columns.Add("Job"); Details_DataTable.Columns.Add("Degree"); Details_DataTable.Columns.Add("Exp"); Details_DataTable.Columns.Add("Address"); Details_DataTable.Columns.Add("Field"); Details_DataTable.Columns.Add("Exam_Point"); Commit_DV_1.DataSource = Details_DataTable; Commit_DV_1.DataBind(); Commit_DV_2.DataSource = Details_DataTable; Commit_DV_2.DataBind(); Commit_DV_3.DataSource = Details_DataTable; Commit_DV_3.DataBind(); // 抓取使用者所選期別並刷新資料表格 SemesterChanged(int.Parse(Semester_DDL.SelectedValue)); }
private void GetProfDetail(DataTable dataTable, int row) { // semester 使用者所選學期 // Details_DataTable 儲存查詢到的三筆審查委員資料 var semester = int.Parse(Batch_DDL.SelectedValue); //定義Details_DataTable及內部資料行(要有那些欄位) DataTable Details_DataTable = new DataTable(); Details_DataTable.Columns.Add("ID"); Details_DataTable.Columns.Add("Name"); Details_DataTable.Columns.Add("Department"); Details_DataTable.Columns.Add("Job"); Details_DataTable.Columns.Add("Degree"); Details_DataTable.Columns.Add("Exp"); Details_DataTable.Columns.Add("Address"); Details_DataTable.Columns.Add("Field"); Details_DataTable.Columns.Add("Exam_Point"); SqlConnection connection = new SqlConnection(ConStr); DataSet dataSet = new DataSet(); for (int col = 4; col <= 6; col++) { // PF_ID 教師編號 var PF_ID = dataTable.Rows[row][col]; //查詢指令 string Transform_queryString = "SELECT Teacher.ID, Teacher.Name, Teacher.Department, Teacher.Job, Teacher.Degree, Teacher.Exp, Teacher.Address, Teacher.Field, ExamPoint_Log.Exam_Point " + "FROM Teacher CROSS JOIN ExamPoint_Log " + "WHERE (ExamPoint_Log.Batch = " + semester + " OR ExamPoint_Log.Batch = N'0' ) AND (ExamPoint_Log.ID = " + PF_ID + ") AND (Teacher.ID = " + PF_ID + ")"; //將查詢到的資料填入dataset中,名為4、5、6的三個table //註:table名稱乃對應Student_DV的4、5、6列 //資料傳送路徑:SQL -> adapter -> dataset -> 三個Commit_DV SqlDataAdapter dataAdapter = new SqlDataAdapter(); dataAdapter.TableMappings.Add("Table", col.ToString()); connection.Open(); SqlCommand command = new SqlCommand(Transform_queryString, connection) { CommandType = CommandType.Text }; dataAdapter.SelectCommand = command; dataAdapter.Fill(dataSet); connection.Close(); } // 將Commit_DV的資料來源綁定 // 已填入三筆審查委員資料的dataTable Commit_DV_1.DataSource = dataSet.Tables["4"]; Commit_DV_1.DataBind(); Commit_DV_2.DataSource = dataSet.Tables["5"]; Commit_DV_2.DataBind(); Commit_DV_3.DataSource = dataSet.Tables["6"]; Commit_DV_3.DataBind(); }
//當使用者選取Student_GV之中某一特定研究生時, //顯示審查委員資料的三個Commit_DV會分別顯示三名委員的詳細資料 //Student GridView To Commit DetailsView -> STGV2CMDV private void STGV2CMDV(DataTable dataTable, int row) { DataSet dataSet = new DataSet(); //將查詢到的資料填入dataset中,名為4、5、6的三個table //註:table名稱乃對應Student_DV的4、5、6列 //資料傳送路徑:SQL -> adapter -> dataset -> 三個Commit_DV for (int col = 4; col <= 6; col++) { // PF_ID 教師編號 var PF_ID = dataTable.Rows[row][col]; GetProfDetail(PF_ID, dataSet, col.ToString()); } // 將Commit_DV的資料來源綁定 // 已填入三筆審查委員資料的dataSet Commit_DV_1.DataSource = dataSet.Tables["4"]; Commit_DV_1.DataBind(); Commit_DV_2.DataSource = dataSet.Tables["5"]; Commit_DV_2.DataBind(); Commit_DV_3.DataSource = dataSet.Tables["6"]; Commit_DV_3.DataBind(); }