See below for my gridview, codings and stored procedure.
//Gridview
AllowPaging="True"
cellpadding="5"
DataKeyNames="Agent_code"
onrowediting="user_RowEditing"
onrowcancelingedit="user_RowCancelingEdit"
OnRowDeleting="user_RowDeleting"
OnRowUpdating="user_Rowupdating"
Onpageindexchanging="user_PageIndexChanging"
onsorting="user_Sorting"
AutoGenerateColumns="False"
AllowSorting="True"
AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True"
EmptyDataText="There are no data records to display.">
<%--
<%--
<%--
<%--
//Code
protected void user_Rowupdating(object sender, GridViewUpdateEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = (DataTable)Session["user_gridview2"];
string campcode = user_gridview2.DataKeys[e.RowIndex].Value.ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["datastore"]);
SqlCommand cmd = new SqlCommand("update_edit_user", conn);
cmd.Connection = conn;
//Update the values.
GridViewRow row = (GridViewRow)user_gridview2.Rows[e.RowIndex];
DropDownList DropDownList1 = (DropDownList)row.FindControl("DropDownList1");
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");
try
{
conn.Open();
//cmd.CommandText = "update_edit_user";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Camp_id", SqlDbType.NVarChar, 50).Value = DropDownList1.Text.Trim();
cmd.Parameters.Add("@Call_Center", SqlDbType.NVarChar, 50).Value = DropDownList2.Text.Trim();
cmd.Parameters.Add("@Agent_code", SqlDbType.NVarChar, 50).Value = TextBox2.Text.Trim();
cmd.Parameters.Add("@Agent_Lastname", SqlDbType.NVarChar, 50).Value = TextBox4.Text.Trim();
cmd.Parameters.Add("@Agent_Firstname", SqlDbType.NVarChar, 50).Value = TextBox5.Text.Trim();
cmd.Parameters.Add("@User_type", SqlDbType.NVarChar, 50).Value = DropDownList3.Text.Trim();
cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 50).Value = DropDownList4.Text.Trim();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
//lblMessage.Text = "Record Updated successfully";
//Refresh the data
user_gridview2.EditIndex = -1;
bindGrid();
}
catch (Exception ee)
{
lblMessage.Text = ee.Message.ToString();
}
finally
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
public void bindGrid()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["datastore"]);
SqlDataAdapter da = new SqlDataAdapter("select * from P_crm_user", conn);
DataSet ds = new DataSet();
try
{
da.Fill(ds, "P_crm_user");
user_gridview2.DataSource = ds.Tables["P_crm_user"].DefaultView;
user_gridview2.DataBind();
}
catch (Exception ee)
{
lblMessage.Text = ee.Message.ToString();
}
finally
{
ds.Dispose();
ds.Dispose();
conn.Close();
conn.Dispose();
}
}
//Stored Procedure
USE [P_CRM]
GO
/****** Object: StoredProcedure [dbo].[update_edit_user] Script Date: 10/22/2012 11:20:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date:
-- 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;
if @Status ='Update'
-- Insert statements for procedure here
UPDATE [P_CRM].[dbo].[P_crm_user]
SET
Agent_code = Agent_code
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
thanks in advance :)
Vishnujeet KumarPosted Oct 25, 2012, 10:19 AM
hi your SP syntax is not correct below that text is highlighted.
UPDATE [P_CRM].[dbo].[P_crm_user]
SET
Agent_code = Agent_code
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
go this links.
http://www.c-sharpcorner.com/forums/thread/190868/update-button-not-functioning-in-gridview.aspx