grid view problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thiagarajanrsbe
    New Member
    • Jan 2008
    • 5

    grid view problem

    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.......whic h command should use to update the data........and send me sample update code in ADO connection
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to TSDN. Heres an article that may help:
    GridView..::.Ro wEditing Event

    Comment

    • mathewgk80
      New Member
      • Sep 2007
      • 103

      #3
      Hi,
      The sample code is given below.....

      Code:
       protected void gdvPurchase_RowUpdating(object sender, GridViewUpdateEventArgs e)
          {
      
              try
              {
                  GridViewRow row = gdvPurchase.Rows[e.RowIndex];
                  string strPurchaseId = txtPurchaseId.Text;
                  string strProductNameNew = ((TextBox)row.Cells[0].Controls[1]).Text;
                  string strNoOfItems = ((TextBox)row.Cells[1].Controls[1]).Text;
                  int intNoOfItems = int.Parse(strNoOfItems);
                  string strPricePerUnit = ((TextBox)row.Cells[2].Controls[1]).Text;
                  int intPricePerUnit = int.Parse(strPricePerUnit);
                  sqlConRowUpdate = new SqlConnection(strConnectionString);
                  sqlConRowUpdate.Open();
                  SqlCommand SqlCmdRowUpdate = new SqlCommand();
                  SqlCmdRowUpdate.Connection = sqlConRowUpdate;
                  SqlCmdRowUpdate.CommandText = "procUpdatePDetails";
                  SqlCmdRowUpdate.CommandType = CommandType.StoredProcedure;
                  SqlCmdRowUpdate.Parameters.Add("@purchaseid", SqlDbType.VarChar).Value = strPurchaseId;
                  SqlCmdRowUpdate.Parameters.Add("@productname", SqlDbType.VarChar).Value = strProductNameNew;
                  SqlCmdRowUpdate.Parameters.Add("@noofitems", SqlDbType.Int).Value = intNoOfItems;
                  SqlCmdRowUpdate.Parameters.Add("@priceperunit", SqlDbType.Int).Value = intPricePerUnit;
                  SqlCmdRowUpdate.ExecuteNonQuery();
                  gdvPurchase.EditIndex = -1;
                  gdvPurchase.DataSource = objBusinessLogic.fnSelectPurchaseDetails(txtPurchaseId.Text);
                  gdvPurchase.DataBind();
              }
              catch (Exception excRowUpdating)
              {
                  Response.Write(excRowUpdating.Message.ToString());
      
              }
              finally
              {
                  sqlConRowUpdate.Close();
              }
      
          
          }

      Regards,

      Mathew

      Comment

      • thiagarajanrsbe
        New Member
        • Jan 2008
        • 5

        #4
        Dear Sir,

        im not using any texbox in my gridview.i want to just update the data into the database.....pl s send me the sample code....

        Comment

        Working...