As I not implemented textbox to the columns in GridView, am a bit confused of update function.
My columns in GridView are BoudedFields. Here my GridView:-
GridLines="None" DataKeyNames="customerId"
Width="100%" onrowcancelingedit="gvCustomers_RowCancelingEdit"
onrowdeleting="gvCustomers_RowDeleting" EnableModelValidation="True"
onrowupdating="gvCustomers_RowUpdating"
style="font-weight: 700">
I did the coding in SQL SP and Customer SP class. I need your help in the coding in .aspx.cs file, i.e Gridview_RowUpdating Event.
1) SQL SP:-
ALTER PROCEDURE customerEdit
@customerId numeric(18,0) ,
@customerCode int,
@firstName varchar(50),
@lastName varchar(50),
@Gender varchar(50),
@Address varchar(50),
@City varchar(50),
@State varchar(50),
@Country varchar(50),
@pinCode bigint,
@mobileNo bigint,
@Email varchar(50),
@joinDate smalldatetime,
@userName varchar(50),
@Password varchar(50)
AS
update tbl_Customer set customerCode=@customerCode,firstName=@firstName,lastName=@lastName,Gender=@Gender,
Address=@Address,City=@City,State=@State,
Country=@Country,pinCode=@pinCode,mobileNo=@mobileNo,Email=@Email,joinDate=@joinDate,userName=@userName,
Password=@Password where customerId=@customerId
RETURN
2) Finally, CustomerSP class:-
public void customerEdit(CInfo InfoCustomer)
{
try
{
if (sqlCon.State == ConnectionState.Closed)
{
sqlCon.Open();
}
SqlCommand c = new SqlCommand("customerEdit", sqlCon);
c.CommandType = CommandType.StoredProcedure;
c.Parameters.Add("customerId", SqlDbType.Decimal).Value = InfoCustomer.customerId;
c.Parameters.Add("customerCode", SqlDbType.Int).Value = InfoCustomer.customerCode;
c.Parameters.Add("firstName", SqlDbType.VarChar).Value = InfoCustomer.firstName;
c.Parameters.Add("lastName", SqlDbType.VarChar).Value = InfoCustomer.lastName;
c.Parameters.Add("Gender", SqlDbType.VarChar).Value = InfoCustomer.Gender;
c.Parameters.Add("Address", SqlDbType.VarChar).Value = InfoCustomer.Address;
c.Parameters.Add("City", SqlDbType.VarChar).Value = InfoCustomer.City;
c.Parameters.Add("State", SqlDbType.VarChar).Value = InfoCustomer.State;
c.Parameters.Add("Country", SqlDbType.VarChar).Value = InfoCustomer.County;
c.Parameters.Add("pinCode", SqlDbType.BigInt).Value = InfoCustomer.pinCode;
c.Parameters.Add("mobileNo", SqlDbType.BigInt).Value = InfoCustomer.mobileNo;
c.Parameters.Add("Email", SqlDbType.VarChar).Value = InfoCustomer.Email;
c.Parameters.Add("joinDate", SqlDbType.SmallDateTime).Value = InfoCustomer.joinDate;
c.Parameters.Add("userName", SqlDbType.VarChar).Value = InfoCustomer.userName;
c.Parameters.Add("Password", SqlDbType.VarChar).Value = InfoCustomer.Password;
int inCount = c.ExecuteNonQuery();
if (inCount > 0)
{
HttpContext.Current.Response.Write("");
}
}
catch (Exception)
{
throw;
}
finally
{
sqlCon.Close();
}
please provide me the information that how to do updation in this GridView.

Sanjeeb LenkaPosted Sep 2, 2013, 2:29 AM
yes looks correct and remove this line
gvCustomers.DataBind();
and you have to pass these values to sp class:
sample:
decimal decId = Convert.ToDecimal(gvCustomers.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)gvCustomers.Rows[e.RowIndex];
TextBox textUName = (TextBox)row.Cells[1].Controls[0];
TextBox textName = (TextBox)row.Cells[2].Controls[0];
TextBox textcode = (TextBox)row.Cells[3].Controls[0];
TextBox txtPhone = (TextBox)row.Cells[4].Controls[0];
TextBox txtDate = (TextBox)row.Cells[5].Controls[0];
CSP sp = new CSP();
CInfo Info = new CInfo();
Info.ID=decId ;
Info.Uname=textUName.Text;
........................................
//write all the code to catch the values like above line
.........................................
sp.customerEdit(Info);
gvCustomers.DataBind();
GridFill();
Bineesh ViswanathPosted Sep 2, 2013, 4:47 AM
Thank you for your help
Sanjeeb LenkaPosted Sep 2, 2013, 3:38 AM
Prasenjit DeyPosted Sep 2, 2013, 2:55 AM
Bineesh ViswanathPosted Sep 2, 2013, 2:47 AM
I given data type SmallDateTime and check the error:-
Is there any way to alter data type in SQL Table?.
Bineesh ViswanathPosted Sep 2, 2013, 2:19 AM
Now I want is that when I click Update button, i want to funtion the record update process.
Here the gvCustomer_RowUpdating Event. please check it whether right or wrong.
decimal decId = Convert.ToDecimal(gvCustomers.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)gvCustomers.Rows[e.RowIndex];
TextBox textUName = (TextBox)row.Cells[1].Controls[0];
TextBox textName = (TextBox)row.Cells[2].Controls[0];
TextBox textcode = (TextBox)row.Cells[3].Controls[0];
TextBox txtPhone = (TextBox)row.Cells[4].Controls[0];
TextBox txtDate = (TextBox)row.Cells[5].Controls[0];
CSP sp = new CSP();
CInfo Info = new CInfo();
sp.customerEdit(Info);
gvCustomers.EditIndex = -1;
gvCustomers.DataBind();
GridFill();
Sanjeeb LenkaPosted Sep 2, 2013, 1:21 AM
follow this code:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int customerId = Convert.ToInt32(gvCustomers.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)gvCustomers.Rows[e.RowIndex];
TextBox textUName = (TextBox)row.Cells[1].Controls[0];
TextBox textName = (TextBox)row.Cells[2].Controls[0];
TextBox textcode = (TextBox)row.Cells[3].Controls[0];
GridView1.EditIndex = -1;
gvbind();
}
here i mention some of the field you mention all the field and pass these values to sp class.