C# Cart Quantity Refresh GridView Textbox Control

Jul 10 2015 10:11 PM

I'm trying to retrieve an Int value from Textbox of each row on GridView, this Textbox is in into ItemTemplate, and the problem is when I have 2 products on cart and change the quantity of second one, and click refresh it only retrieve the value of 1st product and quantity becomes same as 1st product, example if I have 20 products x, and want to put 44 products y, when I click refresh, it check the 1st textbox and retrieve the 1st product Textbox value, 20. Resuming, it only validate the 1st textbox value control of gridview and ignore rest Textboxes (I have done all tests with breakpoint, that's why I have this conclusion).

There's the code:
 
protected void imgbtnrefresh_Click(object sender, ImageClickEventArgs e)
{
ImageButton lnksender = (ImageButton)sender;
Session["Idcarrinho"] = Convert.ToInt32(lnksender.CommandArgument);
try
{
foreach (GridViewRow di in GridView1.Rows)
{
TextBox txtQuantcarrinho = (TextBox)di.FindControl("txtQuantcarrinho");
if (txtQuantcarrinho.Text == "0")
{
string stringconn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
BLL.BD oDB = new BLL.BD(stringconn);
int num = oDB.ApagarCarrinho2(Convert.ToInt32(Session["Idcarrinho"]));
GridView1.DataBind();
int rowCount = GridView1.Rows.Count;
if (rowCount == 0)
{
Response.Redirect("Index.aspx");
}
}
else
{
string stringconn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
BLL.BD oDB = new BLL.BD(stringconn);
int num = oDB.AlterarQuantidade2(Convert.ToInt32(Session["Idcarrinho"]), Convert.ToInt32(txtQuantcarrinho.Text));
if (num == 1)
{
GridView1.DataBind();
}
else
{
}
}
}
}