Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Gridview
if i click on the update button in gridview then i want that the text of the click button will be change but other button have same contaxt... plzz tell me how can i use for loop ...send me code.. my code is
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = GridView1.EditIndex;
GridViewRow row = GridView1.Rows[index];
TextBox t1 = row.FindControl("txtemp_name") as TextBox;
TextBox t2 = row.FindControl("txtemp_add") as TextBox;
TextBox t3 = row.FindControl("txtemp_mob") as TextBox;
TextBox t4 = row.FindControl("txtsalary") as TextBox;
string t5= GridView1.DataKeys[e.RowIndex].Value.ToString();
string dt = "update employee set emp_name='" + t1.Text + "',emp_add='" + t2.Text + "',emp_mob='" + t3.Text+ "',salary='" + t4.Text+ "'where emp_id=" + t5+ "";
con.Open();
cmd = new SqlCommand(dt, con);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
bind();
 
}
Posted 29-Aug-12 22:07pm
Edited 30-Aug-12 9:54am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi.
 
try this
If(Gridview1.RowUpdated==True)
{
button.text="Changed!";
}
  Permalink  
Comments
Rashid Choudhary at 30-Aug-12 4:24am
   
i want to add a for loop. if i update the text and click on the update button such as on..after click the button the gridview is updated and the text will changed of the button is off.
Rashid Choudhary at 30-Aug-12 4:24am
   
and other button text not changed
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = GridView1.EditIndex;
GridViewRow row = GridView1.Rows[index];
TextBox t1 = row.FindControl("txtemp_name") as TextBox;
TextBox t2 = row.FindControl("txtemp_add") as TextBox;
TextBox t3 = row.FindControl("txtemp_mob") as TextBox;
TextBox t4 = row.FindControl("txtsalary") as TextBox;
string t5= GridView1.DataKeys[e.RowIndex].Value.ToString();
string dt = "update employee set emp_name='" + t1.Text + "',emp_add='" + t2.Text + "',emp_mob='" + t3.Text+ "',salary='" + t4.Text+ "'where emp_id=" + t5+ "";
con.Open();
cmd = new SqlCommand(dt, con);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
bind();
Button b1=row.FindControl("yourbuttonname") as Button;
b1.Text="Off"; 
}
  Permalink  
Comments
Rashid Choudhary at 30-Aug-12 4:37am
   
its not work

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



Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100