Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
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();
                                    }
                                }

Thank for advance replay
Posted
Updated 1-Dec-11 21:54pm
v3
Comments
[no name] 2-Dec-11 1:55am    
EDIT: added "pre" tag and edit typos
Dinesh Mani 2-Dec-11 8:13am    
Can you elaborate your query and can you post your entire method, masking the "sensitive" text??
Joel Clark 2-Dec-11 21:39pm    
First of all you should create bound fields in the gridview and convert them to a template field. Then untick generate columns automatically.

Edit the template, add a textbox as an item under the appropriate header. Select ID in properties and call it something like "ColumnName-Relatedinformation" where columnname corrosponds to the column it is in & relatedinformation corrosponds to the information it holds.

you can then create a foreach statement corrosponding to the amount of rows in the grid, and logically grab the information from each textbox in each row.

Sorry if thats confusing but you havent given me much to work with.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900