GridView 把某一列設置爲在編輯狀態時是 DropDownList 下拉選項

右鍵,對改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());

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章