Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, When I wnat to read the New value from the gridview OnRowUpdating with this code

C#
string abc = ((TextBox)Gridview1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;

It only showing the old value hot to get the new value..
please help me..... I want to update it with new values..
Posted
Updated 2-Jun-13 19:52pm
v2
Comments
Please follow my answer - Solution 3.

It's obvious. Because your GridView is binding everytime on postbacks. If you are binding the GridView in Page_Load event, then check for postbacks. Bind your GridView under Not IsPostBack block. Try this:
C#
if(!IsPostBack)
{
    //Bind your gridview here.
}



--Amit
 
Share this answer
 
You can use OnRowUpdated event of gridview....
In this event u can fetch updated new value
 
Share this answer
 
C#
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
            GridViewRow row = GridView1.Rows[e.RowIndex];
            string constr = ConfigurationManager.ConnectionStrings["connstr"].ToString();
            SqlConnection con = new SqlConnection(constr);

            string id = (((Label)row.FindControl("lblid")).Text).ToString();

            string comments = (((TextBox)row.FindControl("txtcomments")).Text).ToString();
           // string grant = (((CheckBox)row.FindControl("CheckBox1")).Checked).ToString();

            if (((CheckBox)row.FindControl("CheckBox1")).Checked == true)
                {
                    con.Open();
                    SqlCommand CmdSql = new SqlCommand("Update leave set admin_comments='" + comments + "', granted='" + true + "' where id=" + id + " ", con);
                    CmdSql.ExecuteNonQuery();
                    GridView1.EditIndex = -1;
                    con.Close();
                    gridpop();
                }

                else
                {
                    con.Open();
                    SqlCommand CmdSql = new SqlCommand("Update leave set admin_comments='" + comments + "', granted='" + false + "' where id=" + id + " ", con);
                    CmdSql.ExecuteNonQuery();
                    GridView1.EditIndex = -1;
                    con.Close();
                    gridpop();

                }
    }
 
Share this answer
 
v2
Comments
_Amy 3-Jun-13 2:31am    
Reason for DownVoting : I don't think the OP is looking for this.

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