右鍵,對改GRIDVIEW編輯列,選中需要修改的那一列,轉換成模版,編輯模版,找到這一列
把裏面的文本框改成DropDownList 保存
回到GridView2_RowUpdating, 取值的這一列改成
string WarrantyStatus = ((DropDownList)(GridView2.Rows[e.RowIndex].Cells[14].Controls[0].FindControl("DropDownList1"))).Text;
經測試已經成功。
SqlConnection conn = new SqlConnection("server=。;uid=sa;pwd=*;database=DB");
conn.Open();
string strSQL = "update ComplaintInf set SerialNumber='" + SerialNumber +
"', CustomerName='" + CustomerName + "', ContactNo='" + ContactNo + "', Address='"
+ Address + "', Area='" + Area + "', City='" + City + "', Region='"
+ Region + "', Model='" + Model + "', Category='" + Category + "', DOP='"
+ DOP + "', Symptom='" + Symptom + "', WarrantyStatus='" + WarrantyStatus + "' , Comments='" + Comments + "', SoluteState='" + SoluteState + "' where id='" + i + "'";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int h = cmd.ExecuteNonQuery();
if (h > 0)
{
Response.Write("<script>alert('success')</script>");
GridView2.EditIndex = -1; //一定要設置,否則還處於編輯狀態
}
else
Response.Write("<script>alert('success')</script>");
bind(sstxt.Text.Trim());