Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble getting unique id for each control after looping a table row
    text
    copied!<p>i am looping the entire table along with the controls. For each row the user can enter a number to perform a calculation and display in a label on that same row but it keeps on affecting all the rest of the rows because their in a loop so there is no unique id for each control.</p> <p>[code]</p> <pre><code>&lt;%@ Page Title="" Language="VB" MasterPageFile="~/public.master" AutoEventWireup="false" CodeFile="ccalc.aspx.vb" Inherits="ccalc" %&gt; &lt;%@ Import Namespace="System.Data" %&gt; &lt;%@ Import Namespace="System.Data.OleDb" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"&gt; &lt;div&gt; &lt;h1&gt;Estimated Monthly Electricity Consumption Calculator&lt;/h1&gt; &lt;/div&gt; &lt;div&gt; &lt;% Dim id As Integer Dim catname As String Dim db As New databaseconnection Dim cmd As New OleDbCommand cmd.Connection = db.connection cmd.CommandText = "select * from ecg_projectDB2.dbo.DeviceCategory" cmd.CommandType = CommandType.Text Dim dr As OleDbDataReader dr = cmd.ExecuteReader Dim found As Boolean = False While dr.Read found = True id = dr("CategoryID") catname = dr("CategoryName") %&gt; &lt;table width="100%" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF" class="ten"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td colspan="5"&gt;&lt;h2&gt;&lt;% Response.Write(catname)%&gt;&lt;/h2&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr align="center"&gt; &lt;th class="style1" bgcolor="#FFCC66"&gt;Electrically Powered Items&lt;/th&gt; &lt;th class="ten" bgcolor="#FFCC66"&gt;&lt;div align="center"&gt;Quantity&lt;/div&gt;&lt;/th&gt; &lt;th class="ten" bgcolor="#FFCC66"&gt;&lt;div align="center"&gt;Average monthly KWh&lt;/div&gt;&lt;/th&gt; &lt;th class="ten" bgcolor="#FFCC66"&gt;&lt;div align="center"&gt;KWh/month&lt;/div&gt;&lt;/th&gt; &lt;th class="ten" bgcolor="#FFCC66"&gt;&lt;div align="center"&gt;GHc /month&lt;/div&gt;&lt;/th&gt; &lt;/tr&gt; &lt;% Dim appid As Integer Dim appname As String Dim wpm As Single Dim brb As New OleDbCommand brb.Connection = db.connection brb.CommandText = "select * from ecg_projectDB2.dbo.Appliances where CategoryID = '" &amp; id &amp; "'" brb.CommandType = CommandType.Text Dim br As OleDbDataReader br = brb.ExecuteReader Dim ins As Boolean = False Dim counter As Integer = 0 While br.Read ins = True appid = br("ApplianceID") 'quantity.ID = appid kwh.ID = appid ghc.ID = appid appname = br("ApplianceName") wpm = br("Wattpermin") counter = counter + 1 Dim qid = quantity.id Dim kwhid = kwh.ID Dim totusage As Single 'Label1.Text = quantity.ID If IsPostBack Then Dim aaa = quantity.ID If counter Then 'Dim MainContent As ContentPlaceHolder = CType(Page.Master.FindControl("MainContent") kwh.Text = quantity.UniqueID 'kwh.Text = Results.text End If End If %&gt; &lt;tr&gt; &lt;td class="style1"&gt;&lt;strong&gt;&lt;% Response.Write(appname)%&gt;&lt;/strong&gt;&lt;/td&gt; &lt;td class="highlight"&gt;&lt;div align="center"&gt; &lt;asp:TextBox ID="quantity" runat="server" AutoPostBack="True" CssClass="input" Width="79px" &gt;&lt;/asp:TextBox&gt; &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div align="center"&gt; &lt;input name="refrigeratorMonthKWh" value="182" type="hidden" /&gt; &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div align="center"&gt; &amp;nbsp;&lt;asp:TextBox ID="kwh" runat="server" CssClass="input4" Width="59px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div align="center"&gt; &amp;nbsp;&lt;asp:TextBox ID="ghc" runat="server" CssClass="input4" Width="59px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% End While brb.Dispose() br.Close() %&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;% End While cmd.Dispose() dr.Close() %&gt; &lt;/div&gt; &lt;% %&gt; &lt;div&gt; &lt;table width="100%" border="0" cellpadding="5" bgcolor="#FFF7E5" class="ten"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;font color="#9f7f40"&gt;Estimated&lt;/font&gt; monthly &lt;u&gt;&lt;font color="#FF0000"&gt;household &lt;/font&gt;&lt;/u&gt;* usage: &lt;asp:TextBox ID="totalusage" runat="server" CssClass="input4" Width="59px"&gt;&lt;/asp:TextBox&gt; &amp;nbsp;kWh; &lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="highlight"&gt;&lt;font color="#9f7f40"&gt;Estimated&lt;/font&gt; monthly &lt;u&gt;&lt;font color="#FF0000"&gt;household&lt;/font&gt;&lt;/u&gt;* bill: &amp;cent; &lt;asp:TextBox ID="totalbill" runat="server" CssClass="input4" Width="59px"&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="highlight"&gt;&lt;h3&gt;&lt;strong&gt;&lt;em&gt;*Heating usage not included in household totals&lt;/em&gt;&lt;/strong&gt;&lt;/h3&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt; &lt;/asp:Content&gt; </code></pre> <p>[/code]</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