Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have a grid with template fields which includes item templates and edit item templates.
While editing any row it is not showing updated value into the string(city).
Please help me

C#
string id = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label4")).Text;
string city = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3")).Text;
Posted

C#
//for example see this 

//in gridview put this property 
// DataKeyNames="Id"


 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        int id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        Label id = (TextBox)row.FindControl("Label4");
        TextBox city = (TextBox)row.FindControl("TextBox3");
        SqlCommand cmd = new SqlCommand("update query ", con);
        
//for example of update query
   
//update tablename set column=city.text where id=convert.toint16(id.text) ;  
 
        con.Open();
        cmd.ExecuteNonQuery();
        GridView1.EditIndex = -1;
        bind();
    }
 
Share this answer
 
string city = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3");


Try this
 
Share this answer
 

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