我在我的asp.net項目中有一個表格,我在運行時動態地將一些按鈕添加到某些單元格。我基於從數據庫中獲取的數據添加這些按鈕。用戶從下拉列表中選擇一個項目,然後單擊顯示計劃按鈕並填寫表格。下面是某一條我的代碼:如何在asp.net中刷新表格UI的數據變化?
for (int i = startindex; i < endindex; i++)
{
Button b = new Button();
b.Text = subj + " " + numb + " " + section;
b.Attributes.Add("onclick", "popWin()");
b.CssClass = "roundedbuttons";
Color clr = getCourseColor(subj + numb + section, courses);
b.BackColor = Color.Aqua;
b.Enabled = true;
b.EnableViewState = true;
b.UseSubmitBehavior = false;
b.UseSubmitBehavior = false;
b.Click += new EventHandler(btn_Click);
string cellPosition = (i).ToString() + ";" + (dayindex).ToString();
b.CommandArgument = cellPosition;
table_row_click = true;
table_filter_instructor_schedule.Rows[i].Cells[dayindex].Controls.Add(b);
pageControls.Add(new PageControls(i, dayindex, null, subj + " " + numb + " " + section, "button"));
visualTable = table_filter_instructor_schedule;
}
這裏是表的樣子:
然後,在某些時候,我更新數據庫,並更改了一些數據,當用戶按下保存更改按鈕:
string selectedRooom = dropdown_available_rooms.SelectedValue.ToString();
var values = selectedRooom.Split(' ');
string newbldg = values[0], newroom = values[1];
btnPopUp_ModalPopupExtender.Hide();
//Update the database, and put the course to its new hours
//term şimdilik
SqlCommand commnd = new SqlCommand("UPDATE Timetable SET [email protected], [email protected], [email protected], [email protected], [email protected] WHERE [email protected] AND [email protected] AND [email protected] AND term='201101' AND [email protected] AND [email protected]", CommonFunctions.con);
commnd.Parameters.AddWithValue("@newstarthour", selected_new_starthour);
commnd.Parameters.AddWithValue("@newendhour", selected_new_endhour);
commnd.Parameters.AddWithValue("@newday", selected_new_day);
commnd.Parameters.AddWithValue("@newbuilding", newbldg);
commnd.Parameters.AddWithValue("@newroom", newroom);
commnd.Parameters.AddWithValue("@subj", clicked_course_code);
commnd.Parameters.AddWithValue("@numb", clicked_course_number);
commnd.Parameters.AddWithValue("@section", clicked_course_section);
commnd.Parameters.AddWithValue("@starthour", clicked_course_starthour);
commnd.Parameters.AddWithValue("@endhour", clicked_course_endhour);
commnd.ExecuteNonQuery();
一切工作正常,直到那一點。問題是,這些變化並沒有反映在可視化表格中,有些按鈕的位置(單元格)必須在表格中進行更改。如果我轉到另一個頁面,然後重新打開具有此可視表格的頁面,表格會更新並正常工作。但是,在用戶單擊保存更改按鈕後,更改不會立即在表格中看到。即使CausesValidation屬性設置爲true,保存更改按鈕也不會導致回發。我不知何故需要重新加載頁面。我試過:
Response.Redirect(Request.RawUrl);
數據更新後,但這次頁面重新加載,自然表中顯示爲空。
那麼,誰能幫助我呢?
謝謝。
每次更新後都必須重新調整表格。 – Fals