本來是想模仿C/S的樣子完成單擊一列直接觸發事件,後來知道那樣要用到AJax,最後還是用了RadioButton這樣實現起來相對簡單,不過只能在要求不高是時候用。
使用這個先要在gridvIEw 裡放入RadioButton模板。然後激發它的checked事件然後在此事件裡可以捕捉到點的那一列,要注意就是點完了要將RadioButton的checked設置為false,這樣看不到剛點過的痕跡,不過也算湊合能是些頭的任務.....
protected void OrdersGridVIEw_ClickChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in this.OrdersGridVIEw.Rows)
{
RadioButton radioButton = (RadioButton)row.FindControl("RadioButton1");
if (radioButton.Checked)
{
//顯示從表內容
int i = Convert.ToInt32(radioButton.Text);
string sqlstr = "SELECT * FROM [Order Details] where orderID=''" + i + "'' ORDER BY [OrderID]";
string TableName = "OrderDetails";
GridViewBind(sqlstr, TableName, OrderDetailsGridVIEw);
radioButton.Checked = false;
}
}
/// <summary>
/// 根據tablename和sql語句綁定GridVIEw1到數據庫
/// </summary>
/// <param name="sqlstr"></param>
/// <param name="tablename"></param>
/// <param name="GridVIEw1"></param>
protected void GridVIEwBind(string sqlstr, string tablename,