返回首页


using System.Configuration;

 

protected void btnUpdae_Click(object sender, EventArgs e)

{

 string connection = ConfigurationManager.ConnectionStrings["QuestionnaireConnection"].ConnectionString;

  using (SqlConnection con = new SqlConnection(connection))

    {

        con.Open();

 

       //Button is outside Gridview and no command argument or command name is given 

       //UserProfileDataContext UR = new UserProfileDataContext(); 

       //if (!IsPostBack)  



        //[here the row count is zero 

        if (grdView.Rows.Count > 0)

          {

 

            //[if I have break point here I am not getting into the loop] 

            foreach (GridViewRow row in grdView.Rows) 

                    {

                        for (int i = 0; i < grdView.Rows.Count; i++)

                        {

                            for (int txtComments = 0; txtComments < grdView.Columns.Count; txtComments++)

                            {

                                

                                Question qs = new Question();

                                string name = Request.QueryString["UserName"];

                                string temp1 = grdView.Rows[i].Cells[0].Text;

 

                                //string temp2 =(TextBox)grdView.Rows[i].Cells[3].FindControl("txtComments")

                                TextBox t1 = (TextBox)grdView.Rows[i].Cells[3].FindControl("txtComments");

 

                                string temp2 = t1.Text;

                                //SqlCommand cmd = new SqlCommand("UPDATE Questionnaire_UserAnswers 

                                //SET Comments='" +    

                                //temp2 + "' WHERE Question_ID='" + temp1 + "'", con);

                                //cmd.ExecuteNonQuery();

                                SqlDataAdapter da;

                                da = new SqlDataAdapter("UPDATE Questionnaire_UserAnswers SET Comments='" + temp2 + "'  

                                                        WHERE Question_ID=" + temp1 + "", con);

 

                                DataSet ds = new DataSet();

                                da.Fill(ds);

 



                                if (ds.Tables.Count > 0)

                                {

                                    if (ds.Tables[0] != null)

                                    {

                                        grdView.DataSource = ds.Tables[0];

                                        grdView.DataBind();

                                    }

                                }

感谢提前重播

回答

评论会员: 时间:2
G