VS 2013,ASP.NET 3.5 VB.NET
Page为不同的弹出窗口提供了多个ModalPopupExtender控件。其中一个弹出窗口填充了一个表格,其中包含CheckBoxControls以及向上销售商品的描述。
页码:
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
[snip]
<ajax:ModalPopupExtender
runat="server"
ID="mpeUpsell"
popupControlID="pUpsell"
CancelControlID="bGoBack"
BackgroundCssClass="custBackground"
PopupDragHandleControlID="phDragUpsell"
TargetControlID="bHidden"
Enabled="True" />
<asp:Panel runat="server" ID="pUpsell" style="display:none;">
<div runat="server" class="custPopup">
<div runat="server" id="phDragUpsell">
<h3 style="text-align:center;">
<asp:Label
ID="lUpsellHdr"
runat="server"
Text="Check Out these Add-Ons" />
</h3>
</div>
<asp:Label
ID="lAddOnsText"
runat="server" />
[snip]
<asp:Table
ID="tItems"
runat="server"
style="border: 1px solid black;">
[snip] <asp:Button ID="bNext" runat="server" Text="Next --->" />
</td>
</tr>
</table>
<br />
<br />
</div>
</asp:Panel>
表tItems的填充方式如下:
For Each dr As DataRow In ds.Tables(0).Rows
tr = New TableRow()
tc = New TableCell()
Dim sName As String = "cbItem_" & CInt(dr("ITEM_ID"))
Dim cb As New CheckBox()
cb.ID = sName
cb.Text = dr("ITEM_DESC").ToString.Trim
If CInt(dr("UGICheckOFF")) = 1 Then
cb.Checked = True
Else
cb.Checked = False
End If
[snip formatting]
tc.Controls.Add(cb)
tr.Cells.Add(tc)
tc2 = New TableCell()
Dim sPrice As String = String.Format("{0:C}", dr("ITEM_PRICE"))
tc2.Text = sPrice
[snip formatting]
tr.Cells.Add(tc2)
tItems.Rows.Add(tr)
Next
该表完美填充并显示我何时使用代码隐藏来显示mpeUpsell ModalPopupExtender。
bNext按钮的处理程序如下所示:
Protected Sub bNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bNext.Click
If iItemArray IsNot Nothing Then iItemArray = Nothing ' get rid of it
' Handle the Next Button
Dim iCartID As Integer = -1
iCartID = CInt(Session("CartID"))
' iterate the items and add each to cart if not already in cart
iItemArray = New ArrayList()
For Each tr As TableRow In tItems.Rows
For Each tc As TableCell In tr.Cells
For Each ctl As Control In tc.Controls
If TypeOf (ctl) Is CheckBox Then
Dim cb As CheckBox = CType(ctl, CheckBox)
If cb.Checked Then
'if there are checks create array of item IDs checked.
Dim itemid As Integer = CInt(cb.ID.Replace("cbItem_", ""))
iItemArray.Add(itemid)
End If
End If
Next
Next
Next
[snip]
End Sub
执行处理程序时,tItems.Rows.Count为ZERO且ForEach只是因为表行已消失而失败。
很明显,我错过了一些东西;我无法弄清楚我错过了什么。
谢谢, 约翰。
答案 0 :(得分:1)
解决方案是放弃asp表,因为在这种情况下它不是有状态的。相反,我使用gridview并将数据表绑定到它,并且能够检索值。
感谢。