Connecting Tech Pros Worldwide Forums | Help | Site Map

Data grid updation

Newbie
 
Join Date: Sep 2008
Posts: 12
#1: Sep 25 '08
In my code i am not able to get the new value from thre textbox which got created when we click the edit button. IT is taking the value which is retried from the database. please help...

Expand|Select|Wrap|Line Numbers
  1. protected void qltyGrid_EditCommand(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
  2.     {
  3.         qltyGrid.EditItemIndex = e.Item.ItemIndex;
  4.         BindData();
  5.     }
  6. protected void qltyGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  7.     {
  8.         string cName = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
  9.  
  10.         ShowMsg(cName);
  11.         SqlCommand com = new SqlCommand("update QualityMasters set QltyName='" + cName  + "' where QltyId='" + 2 + "';", con);
  12.         con.Open();
  13.         com.ExecuteNonQuery();
  14.         con.Close();
  15.         qltyGrid.EditItemIndex = -1;
  16.         BindData();
  17.     }

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,131
#2: Sep 25 '08

re: Data grid updation


In your Page Load event....are you performing a DataBind on your GridView?

When you do this all the data that has been entered during editing is deleted...because the data source has been switched. This could be the reason why you cannot retrieve the text from the edit text box.

-Frinny
Newbie
 
Join Date: Sep 2008
Posts: 12
#3: Sep 25 '08

re: Data grid updation


yes it is true. that was the problem. from yesterday i am breaking my head.
thanks a lot.
Reply


Similar .NET Framework bytes