配列を正しい形式で取得して、注文用のテーブルの ASP.net Web ページに配置しようとしています。
順序は次のとおりです。
model_number
comm_category
service
freight
sales_tax
sales
unit_price
price
id_price
現在、次のように出力しています。
model_number
price
unit_price
id_price
sales_tax
sales
service
freight
comm_category
このため、ここのコードを使用して正しい順序で文字列に追加できません:
Public Sub AssocArray_To_String(ByRef Output As System.Text.StringBuilder, ByVal AssocArrayInput As AssocArray)
For iParent As Integer = 0 To AssocArrayInput.Count - 1
Dim intX As Integer = 0
Dim arrParent As AssocArray = TryCast(AssocArrayInput.Item(iParent), AssocArray)
If arrParent Is Nothing Then Continue For
For iChild As Integer = 0 To arrParent.Count - 1
Call buildItems(PHPConvert.ToString(arrParent.Keys(iChild)), PHPConvert.ToString(arrParent.Values(iChild)), intX)
intX += 1
Next iChild
Next iParent
End Sub
Private Sub buildItems(ByVal nameOfItem As String, ByVal itemItself As String, ByVal intX As Integer)
Dim tmpStuff As Decimal = 0.0
Dim qty As Integer = 1
Dim model_number As String = ""
Dim comm_category As String = ""
Dim service As Double = 0
Dim freight As Double = 0
Dim sales_tax As Double = 0
Dim sales As Double = 0
Dim unit_price As Double = 0
Dim price As Double = 0
Dim id_price As Double = 0
If nameOfItem = "model_number" Then
model_number = itemItself
tableLoop += "<tr><td bgcolor=""#CCCCCC""><asp:Label ID=""item_count_" & intX & """ Text=""Label"">" & qty & "</asp:Label></td>"
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""model_number_" & intX & """ Text=""Label"">" & model_number & "</asp:Label></td>"
ElseIf nameOfItem = "comm_category" Then
comm_category = itemItself
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""comm_category_" & intX & """ Text=""Label"">" & comm_category & "</asp:Label></td>"
ElseIf nameOfItem = "service" Then
service = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""service_" & intX & """ Text=""Label"">" & service & "</asp:Label></td>"
ElseIf nameOfItem = "freight" Then
freight = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""freight_" & intX & """ Text=""Label"">" & freight & "</asp:Label></td>"
ElseIf nameOfItem = "sales_tax" Then
sales_tax = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""sales_tax_" & intX & """ Text=""Label"">" & sales_tax & "</asp:Label></td>"
ElseIf nameOfItem = "sales" Then
sales = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""sales_" & intX & """ Text=""Label"">" & sales & "</asp:Label></td>"
ElseIf nameOfItem = "unit_price" Then
unit_price = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""unit_price_" & intX & """ Text=""Label"">" & unit_price & "</asp:Label></td></tr>"
ElseIf nameOfItem = "price" Then
price = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""amount_" & intX & """ Text=""Label"">" & price & "</asp:Label></td>"
ElseIf nameOfItem = "id_price" Then
id_price = Format(Convert.ToDouble(itemItself), "$######.00")
tableLoop += "<td><asp:Label ID=""id_price_" & intX & """ Text=""Label"">" & id_price & "</asp:Label></td>"
End If
End Sub
最終結果は次のとおりです。
<tr><td bgcolor="#CCCCCC"><asp:Label ID="item_count_0" Text="Label">1</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="model_number_0" Text="Label">TTN491-7BW</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="sales_1" Text="Label">3084.63</asp:Label></td>
<td><asp:Label ID="amount_2" Text="Label">3810</asp:Label></td>
<td><asp:Label ID="sales_tax_3" Text="Label">290.37</asp:Label></td>
<td><asp:Label ID="id_price_4" Text="Label">3810</asp:Label></td></tr>
<td bgcolor="#CCCCCC"><asp:Label ID="comm_category_5" Text="Label">X24</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="service_6" Text="Label">51</asp:Label></td>
<td><asp:Label ID="freight_7" Text="Label">384</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="unit_price_8" Text="Label">3135.63</asp:Label></td></tr>
次のように出力する必要があります。
<tr><td bgcolor="#CCCCCC"><asp:Label ID="item_count_0" Text="Label">1</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="model_number_0" Text="Label">TTN491-7BW</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="comm_category_5" Text="Label">X24</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="service_6" Text="Label">51</asp:Label></td>
<td><asp:Label ID="freight_7" Text="Label">384</asp:Label></td>
<td><asp:Label ID="sales_tax_3" Text="Label">290.37</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="sales_1" Text="Label">3084.63</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="unit_price_8" Text="Label">3135.63</asp:Label></td></tr>
<td><asp:Label ID="amount_2" Text="Label">3810</asp:Label></td>
<td><asp:Label ID="id_price_4" Text="Label">3810</asp:Label></td></tr>
配列を正しい順序で配置するにはどうすればよいですか?