By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

grid view problem

P: 5
Dear All,

I have one problem in gridview.Im using C# code and ADO connection.
In the grid view ,data is not updated in the update link....Please hep me to solve this issue.........
Im use grid_Row Editing Event to edit the grid.......which command should use to update the data........and send me sample update code in ADO connection
Jan 25 '08 #1
Share this Question
Share on Google+
3 Replies


kenobewan
Expert 2.5K+
P: 4,871
Welcome to TSDN. Heres an article that may help:
GridView..::.RowEditing Event
Jan 25 '08 #2

100+
P: 103
Hi,
The sample code is given below.....

Expand|Select|Wrap|Line Numbers
  1.  protected void gdvPurchase_RowUpdating(object sender, GridViewUpdateEventArgs e)
  2.     {
  3.  
  4.         try
  5.         {
  6.             GridViewRow row = gdvPurchase.Rows[e.RowIndex];
  7.             string strPurchaseId = txtPurchaseId.Text;
  8.             string strProductNameNew = ((TextBox)row.Cells[0].Controls[1]).Text;
  9.             string strNoOfItems = ((TextBox)row.Cells[1].Controls[1]).Text;
  10.             int intNoOfItems = int.Parse(strNoOfItems);
  11.             string strPricePerUnit = ((TextBox)row.Cells[2].Controls[1]).Text;
  12.             int intPricePerUnit = int.Parse(strPricePerUnit);
  13.             sqlConRowUpdate = new SqlConnection(strConnectionString);
  14.             sqlConRowUpdate.Open();
  15.             SqlCommand SqlCmdRowUpdate = new SqlCommand();
  16.             SqlCmdRowUpdate.Connection = sqlConRowUpdate;
  17.             SqlCmdRowUpdate.CommandText = "procUpdatePDetails";
  18.             SqlCmdRowUpdate.CommandType = CommandType.StoredProcedure;
  19.             SqlCmdRowUpdate.Parameters.Add("@purchaseid", SqlDbType.VarChar).Value = strPurchaseId;
  20.             SqlCmdRowUpdate.Parameters.Add("@productname", SqlDbType.VarChar).Value = strProductNameNew;
  21.             SqlCmdRowUpdate.Parameters.Add("@noofitems", SqlDbType.Int).Value = intNoOfItems;
  22.             SqlCmdRowUpdate.Parameters.Add("@priceperunit", SqlDbType.Int).Value = intPricePerUnit;
  23.             SqlCmdRowUpdate.ExecuteNonQuery();
  24.             gdvPurchase.EditIndex = -1;
  25.             gdvPurchase.DataSource = objBusinessLogic.fnSelectPurchaseDetails(txtPurchaseId.Text);
  26.             gdvPurchase.DataBind();
  27.         }
  28.         catch (Exception excRowUpdating)
  29.         {
  30.             Response.Write(excRowUpdating.Message.ToString());
  31.  
  32.         }
  33.         finally
  34.         {
  35.             sqlConRowUpdate.Close();
  36.         }
  37.  
  38.  
  39.     }

Regards,

Mathew
Jan 25 '08 #3

P: 5
Dear Sir,

im not using any texbox in my gridview.i want to just update the data into the database.....pls send me the sample code....
Jan 28 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.