Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
give me the code or Idea for
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
Posted
Updated 22-Dec-10 22:38pm
v3

HI, this event is used whenever you wanna update a Grid View's Row.
Please read the below link for more Info.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx[^]
 
Share this answer
 
Comments
nupursingh 24-Dec-10 5:13am    
thanx
You can use this event to trap row-wise data binding to grid. Thus, if you need to change color of row or some manipulation at row level before databound, like adding an alert to button click (button present in any one of the cell)
C#
//Something similar to this
protected void Gridview_RowDatabound(object sender, DataGridItemEventArgs e)
{
     Button btn = (Button)e.Row.FindControl("myDeleteButton");
     if (btn != null)
     {
         // you got btn object here. Do any manipulation desired.
         // btn.Text = "Hi There"+someRandomNumber;
         // btn.OnClientClick = "CallMeWhenDeleteIsPressed";
     }
}
 
Share this answer
 
Comments
Sandeep Mewara 23-Dec-10 6:34am    
Any reason?
Tarun.K.S 23-Dec-10 7:22am    
Some gold or platinum univoter is on the loose! Countering but no effect!
nupursingh 24-Dec-10 5:13am    
thank u so much
public void Grid()    {        
            SqlConnection con = new SqlConnection("server=. ; integrated security=sspi; database = Ram");      
            con.Open();       
            SqlDataAdapter da = new SqlDataAdapter("select *  from Ram ", con);       
               
            DataSet ds= new DataSet();       
           da.Fill(ds, "Ram");       
           GridView1.DataSource = ds;       
           GridView1.DataBind();       
           ListBox1.DataSource = ds;      
           ListBox1.DataTextField = ds.Tables[0].Columns[0].ToString();              
           ListBox1.DataBind();       
           con.Close();   
    }


protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)    {       
                           
               Button  lb = new Button();       
               TextBox txt1 = new TextBox();       
               txt1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0];      
               string str1 = Convert.ToString(txt1.Text);          
               TextBox txt4 = new TextBox();       
               txt4 = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0];       
               string str4 = Convert.ToString(txt4.Text);              
               TextBox txt2 = new TextBox();       
               txt2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];       
               string str2 = Convert.ToString(txt2.Text);       
               TextBox txt3 = new TextBox();       
               txt3 = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0];      
               string str3 = Convert.ToString(txt3.Text);              
               SqlConnection con = new SqlConnection("server=. ; integrated security=sspi; database = Ram");      
               con.Open();       
              SqlCommand com = new SqlCommand("update Ram set NAME=@NAME,Fname=@age,address =@address where id=@lname", con);       
              com.Parameters.AddWithValue("@lname", str1);       
              com.Parameters.AddWithValue("@age", str2);       
              com.Parameters.AddWithValue("@address", str3);       
              com.Parameters.AddWithValue("@NAME", str4);       
              com.ExecuteNonQuery();       
              Response.Write("successfully updated");      
              GridView1.EditIndex = -1;       
              Grid();                               
   }
 
Share this answer
 
v2
Comments
nupursingh 24-Dec-10 5:13am    
it helped thanx alot
update database from gridview like this
int _srno = Convert.ToInt32(gdvdata.DataKeys[e.RowIndex].Value.ToString());
TextBox txt1990 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt1990");
TextBox txt1995 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt1995");
TextBox txt2000 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt2000");
TextBox txt2001 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt2001");
TextBox txt2002 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt2002");
TextBox txt2003 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt2003");
TextBox txt2004 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt2004");
TextBox txt2005 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt2005");
TextBox txt2006 = (TextBox)gdvdata.Rows[e.RowIndex].FindControl("txt2006");
if (obj.UpdateData(_srno,txt1990.Text,txt1995.Text,txt2000.Text,txt2001.Text,txt2002.Text,txt2003.Text,txt2004.Text,txt2005.Text,txt2006.Text))
{
gdvdata.EditIndex = -1;
DataSet ds = obj.GetData();
gdvdata.DataSource = ds.Tables[0];
gdvdata.DataBind();
}
 
Share this answer
 
Comments
nupursingh 24-Dec-10 5:13am    
thanks a lot

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