Click here to Skip to main content
15,895,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Below line of code not taken values from grid
C#
string temp2 = grdView.Rows[i].Cells[3].Text;

ASP.NET
<itemtemplate>
                <asp:Label ID="lblComments" runat="server" Text='<%# Bind("Comments") %>'>
                <asp:TextBox ID="txtComments" runat="server">
            </itemtemplate>

Below line of code not taken values from grid
C#
string temp2 = grdView.Rows[i].Cells[3].Text;

C#
protected void btnUpdae_Click(object sender, EventArgs e)
        {
            string connection = System.Configuration.ConfigurationManager.ConnectionStrings["QuestionnaireConnection"].ConnectionString;
            using (SqlConnection con = new SqlConnection(connection))
            {
                con.Open();

                if (grdView.Rows.Count > 0) //[here the row count is zero 
                {
                    foreach (GridViewRow row in grdView.Rows) //[if I have break point here I am not getting into the loop] 
                    {
                        for (int i = 0; i < grdView.Rows.Count; i++)
                        {
                            Question qs = new Question();
                            string name = Request.QueryString["UserName"];
                            string temp1 = grdView.Rows[i].Cells[0].Text;
                            string temp2 = grdView.Rows[i].Cells[3].Text;

                            SqlDataAdapter da;
                            da = new SqlDataAdapter("UPDATE Questionnaire_UserAnswers SET Comments='" + temp2 + "' WHERE Question_ID=" + temp1 + "", con);
                            DataSet ds = new DataSet();

                            da.Fill(ds);
                            grdView.DataSource = ds;
                        }

                        grdView.EditIndex = -1;
                        ShowGridBindData();
                        lblmessage.Visible = true;
                        lblmessage.Text = "Record Updated Successfully";
                    }
                }
Posted
Updated 1-Dec-11 1:28am
v2
Comments
André Kraak 1-Dec-11 7:29am    
Edited question:
Added pre tags
Formatted text/code
Sergey Alexandrovich Kryukov 1-Dec-11 11:19am    
Not a question. What's the problem?
--SA

use data keys is better to get grid values

gridview.DataKeys(e.RowIndex).Values(0).ToString()
 
Share this answer
 
Comments
2011999 1-Dec-11 7:50am    
in button event not taken rowindex
This is the way to find Control And Text value
here we can use Dropdown or any control

GridviewRow row;
C#
string textBoxText = _
         ((TextBox)row.FindControl("TextBox1")).Text;
 
Share this answer
 
use findbycontrol
if you use template fields
 
Share this answer
 
Comments
2011999 1-Dec-11 8:11am    
i used template fields

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