protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow tmpGVR = null;
//取得GridView的工作項目按鍵類別
if (e.CommandSource is ImageButton)
{
ImageButton tmpIBtn = (e.CommandSource) as ImageButton;
tmpGVR = tmpIBtn.NamingContainer as GridViewRow;
}
else if (e.CommandSource is LinkButton)
{
LinkButton tmpLBtn = (e.CommandSource) as LinkButton;
tmpGVR = tmpLBtn.NamingContainer as GridViewRow;
}
// 防呆
if (tmpGVR == null)
return;
//取得key
int tmpRowIndex = tmpGVR.RowIndex;
string tmpPKey = Convert.ToString(GridView1.DataKeys[tmpRowIndex].Value);
//取得GridView的工作項目按鍵
if (e.CommandName == "AR")
{
string tmpID = GridView1.Rows[tmpRowIndex].Cells[4].Text;
Response.Redirect("wfLessonBooking.aspx?les_pkey=" + tmpPKey + "&les_id=" + tmpID);
}
if (e.CommandName == "PR")
{
string tmpID = GridView1.Rows[tmpRowIndex].Cells[4].Text;
Response.Redirect("wfLessonBooking.aspx?les_pkey=" + tmpPKey + "&les_id=" + tmpID);
}
}
類型2(Main_F22_wfDefAID.cs)
protected void gvMainData_RowCommand(object sender, GridViewCommandEventArgs e)
{
//btnUpdateAID
if (e.CommandName == "btnUpdateAID")
{
//1.先找到button Row
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
//2.找到Row Index
int RowIndex_ = row.RowIndex; // e.CommandArgument ;// int.Parse(e.CommandArgument.ToString());
//3.找Row 內的 TextBox 元件
TextBox txtadress = (TextBox)row.FindControl("TextBox1");
string pkey = gvMainData.DataKeys[RowIndex_].Value.ToString();
string newData = txtadress.Text;
SqlHelper.ExecuteNonQuery(ConDB, CommandType.Text, "update DeployDevice set DeployDevice_Version='" + newData + "' where DeployDevice_Id='" + pkey + "' ");
bind_gvMainData();
}
}