I'm having some problem getting text from a text box in a row that has been checked in a gridview. When the button is pressed, it should get the check row index for prodID and the amount, which is the text from the text field:
protected void lbnConfirm_Click(object sender, EventArgs e)
{
string quantity = "" , prodID = "";
foreach (RepeaterItem item in Repeater1.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
Panel pnl = item.FindControl("pBody1") as Panel;
GridView gv = pnl.FindControl("gvProduct") as GridView;
foreach (GridViewRow gr in gv.Rows)
{
CheckBox cb = (CheckBox)gr.Cells[0].FindControl("cbCheckRow");
if (cb.Checked)
{
prodID = gv.DataKeys[gr.RowIndex].Value.ToString();
var tbQuantity = gr.FindControl("tbQuantity") as TextBox;
if (tbQuantity != null)
{
quantity = tbQuantity.Text;
}
tempList.Add(prodID);
}
}
}
}
for (int i = 0; i < tempList.Count; i++)
{
lblTest.Text += tempList[i] + " " + quantity;
}
}
Say I got prodID 1 with 50 units, prodID 2 with 77 units, prodID 3 with 90 units. When I loop through tempList, this is the result I should get:
1 50units, 2 77units, 390units
However, the codes do not receive the amount from the text box for each product independently. Here is the result I get:
1 90units, 2 90units, 3 90units
Just just get the amount of the last product listed. I wonder if there is a way to fix this? Thanks in advance.
Edited Part:
foreach (string key in tempList.Keys)
{
packagesNeeded = 1;
unitQty = prodPackBLL.getUnitQtySPU(tempList[key]);
lblTest.Text += key + " " + tempList[key];
if (Convert.ToInt32(quantity) < (packagesNeeded * unitQty))
{
Page.ClientScript.RegisterStartupScript(GetType(), "UserDialogScript", "alert(\"Insufficient storage\");", true);
}
}