Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting textBox value of checked row in grid view
    text
    copied!<p>I am having some problem for getting the text from textbox in a row which the checkbox was marked check in gridview. When button on click, it supposed to get the checked row index for prodID and the quantity which is the text from textbox:</p> <pre><code>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) { //Get the productID which set as DataKeyNames for selected row index 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 &lt; tempList.Count; i++) { //Testing lblTest.Text += tempList[i] + " " + quantity; } } </code></pre> <p>Let's say I got prodID 1 with 50 units, prodID 2 with 77 units, prodID 3 with 90 units. When I loop thru the tempList, this is the result which I supposed to get:</p> <pre><code>1 50units, 2 77units, 390units </code></pre> <p>However, the codes does not get the quantity from the textbox for each product independently. Here is the result which I get:</p> <pre><code>1 90units, 2 90units, 3 90units </code></pre> <p>It just simply get the quantity of last product in the list. I wonder is there any way to fix this? Thanks in advance.</p> <p>Edited Portion:</p> <pre><code> foreach (string key in tempList.Keys) { packagesNeeded = 1; unitQty = prodPackBLL.getUnitQtySPU(tempList[key]); lblTest.Text += key + " " + tempList[key]; if (Convert.ToInt32(quantity) &lt; (packagesNeeded * unitQty)) { //Pop up message Page.ClientScript.RegisterStartupScript(GetType(), "UserDialogScript", "alert(\"Insufficient storage\");", true); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload