我正在开发一个简单的婚礼清单应用程序,客人可以在其中预订他们想为新娘和新郎购买的礼物。Reserve 页面在几个面板中封装了一些字段,所有面板都封装在 FormView 中。
用户输入他们的姓名、电子邮件和他们想要预订的项目数量,页面将在数据库中进行必要的预订。
我的第一个问题是,在 FormView_ItemCommand 中,我无法引用 FormView 中的任何其他控件......对于 ListViews 或 DetailViews?
其次,我知道以下代码有效..
Dim oCtrl as TextBox = Me.fvwReservation.FindControl("txtEmail")
Dim Test As String = oCtrl.Text
...但是为什么我不能使用...
Dim Test As String = Me.fvwReservation.FindControl("txtEmail").Text
??
最后,我认为这次不需要它,但我一直在研究递归 FindControl 变体,但实际上我还没有找到真正编译的变体!有什么建议么?
一篇文章很多 - 在此先感谢。
免费代码片段:
<asp:FormView ID="fvwReservation" runat="Server" DataSourceID="dsGift">
<ItemTemplate>
<asp:Panel runat="server" ID="pnlDetails">
<h3>Reserve Item: <%#Eval("ShortDesc")%></h3>
<p>You have chosen to reserve the <em><%#Eval("LongDesc")%></em> gift.</p>
<p>Please enter your details below to confirm the reservation.</p>
</asp:Panel>
<asp:Panel runat="server" ID="pnlConfirm">
<div class="row">
<asp:Label runat="server" CssClass="label">Name:</asp:Label><asp:TextBox ID="txtName" MaxLength="50" runat="server" CssClass="Field" />
<asp:RequiredFieldValidator ID="rfvName" runat="server" ErrorMessage="You must specify your Name" ControlToValidate="txtName" />
</div>
<div class="row">
<asp:Label runat="server" CssClass="label">Email:</asp:Label><asp:TextBox ID="txtEmail" MaxLength="100" runat="server" CssClass="Field"/>
<asp:RequiredFieldValidator ID="rfvEmail" runat="server" ErrorMessage="You must specify your Email Address" ControlToValidate="txtEmail" />
<asp:RegularExpressionValidator ID="regexEmail" ValidationExpression="^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$" runat="server" ErrorMessage="Please enter a valid Email Address" ControlToValidate="txtEmail" />
</div>
<div class="row">
<asp:Label runat="server" CssClass="label">Quantity (max <%#Eval("QtyRemaining")%>):</asp:Label><asp:TextBox ID="iQty" MaxLength="2" runat="server" CssClass="Field" />
<asp:RangeValidator ID="rvQty" runat="server" ErrorMessage="The Quantity mmust be between 1 and 10" MinimumValue="1" MaximumValue="10" ControlToValidate="iQty" />
</div>
<div class="row">
<asp:Label runat="server" CssClass="label"> </asp:Label>
<asp:Button ID="btnReserve" Text="Confirm Reservation" CommandName="Reserve" runat="server" />
</div>
</asp:Panel>
</ItemTemplate>
</asp:FormView>