代码改变世界

GridView RowCommand事件操作Demo Code

2008-09-04 11:58  Vincent.C  阅读(191)  评论(0编辑  收藏  举报
  1. //Demo Code 1: 
  2.         protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  3.         {
  4.             switch (e.CommandName)
  5.             {
  6.                 case "RollBack":
  7.                     string index = this.GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();
  8.                     string runcard_id1 = "";
  9.                     string runcard_id2 = "";
  10.                     string sqlStr = "select runcard_id1,runcard_id2 from bak_unit where unit_index='" + index + "' ";
  11.                     DataSet ds = dbc.GetDataSet(sqlStr);
  12.                     if (ds.Tables[0].Rows.Count > 0)
  13.                     {
  14.                         runcard_id1 = ds.Tables[0].Rows[0][0].ToString();
  15.                         runcard_id2 = ds.Tables[0].Rows[0][1].ToString();
  16.                         Lot_Unite_Class luc = new Lot_Unite_Class();
  17.                         luc.Unit_Index = index;
  18.                         luc.Runcard_ID1 = runcard_id1;
  19.                         luc.Runcard_ID2 = runcard_id2;
  20.                         string result = luc.Lot_Unit_Rollback();
  21.                         Alert(result);
  22.                     }
  23.                     break;
  24.                 default:
  25.                     break;
  26.             }
  27.         }
  28.         //Demo Code 2:
  29.         protected void gvCurrentInfo_RowCommand(object sender, GridViewCommandEventArgs e)
  30.         {
  31.             int selectIndex = Convert.ToInt32(e.CommandArgument);
  32.             GridView gridView = (GridView)sender;
  33.             RuncardID = gridView.Rows[selectIndex].Cells[1].Text.ToString();
  34.             StationID = gridView.Rows[selectIndex].Cells[3].Text.ToString();
  35.             switch (e.CommandName)
  36.             {
  37.                 case "JUMPSTATION":
  38.                     divEditAreaVisable(true);
  39.                     break;
  40.                 default:
  41.                     break;
  42.             }
  43.         }