wyndel villanueva

wyndel villanueva

  • NA
  • 14
  • 17.3k

How to enable update in edit gridview

Oct 16 2012 3:14 AM
Please help anyone, on how to activate update in gridview...

thanks in advance.

below is the my code.

  protected void user_Rowupdating(object sender, GridViewUpdateEventArgs e)
  {


  string campid = user_gridview.DataKeys[e.RowIndex].Value.ToString();


 
  //Update the values.
  GridViewRow row = (GridViewRow)user_gridview.Rows[e.RowIndex];
  DropDownList DropDownList2 = (DropDownList)row.FindControl("DropDownList2");
  TextBox TextBox2 = (TextBox)row.FindControl("TextBox2");
  TextBox TextBox3 = (TextBox)row.FindControl("TextBox3");
  TextBox TextBox4 = (TextBox)row.FindControl("TextBox4");
  TextBox TextBox5 = (TextBox)row.FindControl("TextBox5");
  DropDownList DropDownList3 = (DropDownList)row.FindControl("DropDownList3");
  DropDownList DropDownList4 = (DropDownList)row.FindControl("DropDownList4");


  SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["datastore"]);
  SqlCommand cmd = new SqlCommand();

  try
  {
  conn.Open();
  cmd.CommandText = "update_edit_user";
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.Add("@Camp_id", SqlDbType.NVarChar, 50).Value = int_camp_id.Text.Trim();
  cmd.Parameters.Add("@Call_Center", SqlDbType.NVarChar, 50).Value = txt_call_center.Text.Trim();
  cmd.Parameters.Add("@Agent_code", SqlDbType.NVarChar, 50).Value = int_agent_code.Text.Trim();
  cmd.Parameters.Add("@Agent_Lastname", SqlDbType.NVarChar, 50).Value = txt_agent_lname.Text.Trim();
  cmd.Parameters.Add("@Agent_Firstname", SqlDbType.NVarChar, 50).Value = txt_agent_fname.Text.Trim();
  cmd.Parameters.Add("@User_type", SqlDbType.NVarChar, 50).Value = txt_user_type.Text.Trim();
  cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 50).Value = txt_status.Text.Trim();
  cmd.Connection = conn;
  cmd.ExecuteNonQuery();



  //Refresh the data
  user_gridview.EditIndex = -1;
  bindGrid();

  }
  catch (SqlException ee)
  {
  Response.Write(ee.Message);
  }
  finally
  {
  cmd.Dispose();
  conn.Close();
  conn.Dispose();
  }

  }


below is the stored procedure.

USE [P_CRM]
GO
/****** Object:  StoredProcedure [dbo].[update_edit_user]  Script Date: 10/16/2012 15:12:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:    <Author,,Name>
-- Create date: <Create Date,,>
-- Description:  <Description,,>
-- =============================================
  ALTER PROCEDURE [dbo].[update_edit_user]
  -- Add the parameters for the stored procedure here
  --@rid int
  @Camp_Id nvarchar(max)
  ,@Call_Center nvarchar(max)
  ,@Agent_code nvarchar(max)
  ,@Agent_Lastname nvarchar(max)
  ,@Agent_Firstname nvarchar(max)
  ,@User_type nvarchar(max)
  ,@Status nvarchar(max)
 
AS
BEGIN
  -- SET NOCOUNT ON added to prevent extra result sets from
  -- interfering with SELECT statements.
  SET NOCOUNT ON;

  -- Insert statements for procedure here
  UPDATE [P_CRM].[dbo].[P_crm_user]
  SET
  Camp_id = Camp_id
 
  where Camp_Id=@Camp_Id and @Call_Center= Call_Center and Agent_code=@Agent_code and Agent_Lastname = @Agent_Lastname and Agent_Firstname = Agent_Firstname and @User_type = User_type and Status = @Status
 
 
 
END


Answers (2)