Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay error message on gridview row based on textBox value
    text
    copied!<p>I am trying to do like if checkbox is marked on certain rows in gridview, I will check if the user inputs exceed storage level. If exceed, I will display an error message using a label binded just next to the textbox. Here is how I set up my gridview binded in a repeater:</p> <pre><code>&lt;!-- Collapsible panel extender body --&gt; &lt;asp:Panel ID="pBody1" runat="server" CssClass="cpBody"&gt; &lt;asp:Label ID="lblBodyText1" runat="server" /&gt; &lt;!-- Grid view to show products based on each category --&gt; &lt;asp:GridView ID="gvProduct" runat="server" AutoGenerateColumns="False" Width="998px" CellPadding="4" ForeColor="#333333" GridLines="None" ShowHeader="False" DataKeyNames="id"&gt; &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt; &lt;Columns&gt; &lt;asp:TemplateField ItemStyle-HorizontalAlign="Center"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="cbCheckRow" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="name" HeaderText="Name" ItemStyle-Width="650px" /&gt; &lt;asp:BoundField DataField="inventoryQuantity" HeaderText="Total Unit" /&gt; &lt;asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="Center"&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="tbQuantity" runat="server" Width="60" Text='&lt;%# DataBinder.Eval(Container.DataItem, "unitQuantity") %&gt;'/&gt; &lt;asp:Label ID="lblCheckAmount" runat="server" Visible="true" &gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/asp:Panel&gt; </code></pre> <p>Here is the code when button is on click:</p> <pre><code>string quantity = "", prodID = ""; int packagesNeeded = 0, totalUnit = 0; Dictionary&lt;string, string&gt; tempList = new Dictionary&lt;string, string&gt;(); //Get the total packages needed for this distribution packagesNeeded = prodPackBLL.getPackagesNeededByDistributionID(distributionID); 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 and unit quantity from selected row index prodID = gv.DataKeys[gr.RowIndex].Value.ToString(); var tbQuantity = gr.FindControl("tbQuantity") as TextBox; if (tbQuantity != null) { quantity = tbQuantity.Text; } //Add both objects into Dictionary tempList.Add(prodID, quantity); } } } } //Loop thru tempList. key as prodID, tempList.Keys as quantity foreach (string key in tempList.Keys) { //Get total unit of each products totalUnit = prodPackBLL.getTotalProductUnit(key); //Here check if exceed storage if (((Convert.ToInt32(quantity)) * packagesNeeded) &gt; totalUnit) { foreach (RepeaterItem item in Repeater1.Items) { Panel pnl = item.FindControl("pBody1") as Panel; GridView gv = pnl.FindControl("gvProduct") as GridView; foreach (GridViewRow gr in gv.Rows) { Label lblCheckAmount = gr.FindControl("lblCheckAmount") as Label; lblCheckAmount.Text = "Insufficient amount"; } } } } </code></pre> <p>All the checkbox and other things work perfectly. Just that when one record is insufficient, all the row will display the error message even though they are sufficient. What I am trying to do is display error message on the row that are insufficient only. </p> <p>Thanks in advance and sorry for my poor explanation.</p>
 

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