コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SurveyQ        tdList     = new SurveyQ();
            SurveyQDAO     tdDAO      = new SurveyQDAO();
            List <SurveyQ> surveyList = new List <SurveyQ>();

            surveyList           = tdDAO.getSurveyID();
            GridView1.DataSource = surveyList;
            GridView1.DataBind();
            BtnSurvey.Visible = false;
            if (GridView1.Rows.Count < 1)
            {
                Label1.Text       = "<h1 style='text-align:center;'>There are no Surveys at the moment. Create a Survey below!</h1>";
                BtnSurvey.Visible = true;
                GridView1.Enabled = false;
            }
            else
            {
                Label1.Text = "<h2> Current List of Surveys </h2>";
            }
        }
コード例 #2
0
        protected void Click_Delete(object sender, GridViewDeleteEventArgs e)
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);
            string        Id        = GridView1.Rows[e.RowIndex].Cells[0].Text;
            int           result;

            myConn.Open();
            SqlCommand cmd = new SqlCommand("DELETE FROM SurveyQns WHERE SurveyQID ='" + Id + "'", myConn);

            result = cmd.ExecuteNonQuery();
            myConn.Close();
            if (result == 1)
            {
                SurveyQ        surveyObj = new SurveyQ();
                SurveyQDAO     tdDAO     = new SurveyQDAO();
                List <SurveyQ> tdList    = new List <SurveyQ>();
                tdList = tdDAO.getSurveyID();
                GridView1.DataSource = tdList;
                GridView1.DataBind();
            }
        }