コントロールと共にテーブル全体をループしています。行ごとに、ユーザーは数値を入力して計算を実行し、同じ行のラベルに表示できますが、ループ内にあるため、残りのすべての行に影響を与え続け、各コントロールに一意の ID はありません。
[コード]
<%@ Page Title="" Language="VB" MasterPageFile="~/public.master" AutoEventWireup="false" CodeFile="ccalc.aspx.vb" Inherits="ccalc" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<div>
<h1>Estimated Monthly Electricity Consumption Calculator</h1>
</div>
<div>
<%
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")
%>
<table width="100%" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF" class="ten">
<tbody>
<tr>
<td colspan="5"><h2><% Response.Write(catname)%></h2></td>
</tr>
<tr align="center">
<th class="style1" bgcolor="#FFCC66">Electrically Powered Items</th>
<th class="ten" bgcolor="#FFCC66"><div align="center">Quantity</div></th>
<th class="ten" bgcolor="#FFCC66"><div align="center">Average
monthly KWh</div></th>
<th class="ten" bgcolor="#FFCC66"><div align="center">KWh/month</div></th>
<th class="ten" bgcolor="#FFCC66"><div align="center">GHc /month</div></th>
</tr>
<%
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 = '" & id & "'"
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
%>
<tr>
<td class="style1"><strong><% Response.Write(appname)%></strong></td>
<td class="highlight"><div align="center">
<asp:TextBox ID="quantity" runat="server" AutoPostBack="True" CssClass="input"
Width="79px" ></asp:TextBox>
</div></td>
<td><div align="center">
<input name="refrigeratorMonthKWh" value="182" type="hidden" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div></td>
<td><div align="center">
<asp:TextBox ID="kwh" runat="server" CssClass="input4" Width="59px"></asp:TextBox>
</div></td>
<td><div align="center">
<asp:TextBox ID="ghc" runat="server" CssClass="input4" Width="59px"></asp:TextBox>
</div></td>
</tr>
<%
End While
brb.Dispose()
br.Close()
%>
</tbody>
</table>
<%
End While
cmd.Dispose()
dr.Close()
%>
</div>
<%
%>
<div>
<table width="100%" border="0" cellpadding="5" bgcolor="#FFF7E5" class="ten">
<tbody>
<tr>
<td><font color="#9f7f40">Estimated</font> monthly <u><font color="#FF0000">household </font></u>*
usage:
<asp:TextBox ID="totalusage" runat="server" CssClass="input4" Width="59px"></asp:TextBox>
kWh; <br /></td>
</tr>
<tr>
<td class="highlight"><font color="#9f7f40">Estimated</font> monthly <u><font color="#FF0000">household</font></u>*
bill: ¢
<asp:TextBox ID="totalbill" runat="server"
CssClass="input4" Width="59px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="highlight"><h3><strong><em>*Heating usage
not included in household totals</em></strong></h3></td>
</tr>
</tbody>
</table>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
[/コード]