VB.NET Repeater 无需数据源的简单数据绑定

发布于 2024-07-21 08:02:12 字数 7099 浏览 16 评论 0原文

我有一个表单必须是网页上的转发器。 我有一个数字参数,它告诉我要添加多少个额外的客户详细信息。 在此页面中,我有一个转发器控件,需要将项目重复设定的次数。 对于每个项目,都有一组需要附加 id 的输入框。 我需要绑定的只是每个附加输入框的数字,即 <% #id %>。 我不知道如何在没有特定数据源的情况下设置简单的数据绑定,但只是在循环中构建一个。

<asp:Repeater ID="myRepeater" runat="server"> 
    <HeaderTemplate>  
       <div class="AdditionalRowTitle">
            <div class="AdditionalCellTitle">Title</div>
            <div class="AdditionalCellFirstName">First Name</div>
            <div class="AdditionalCellLastName">Last Name</div>
            <div class="AdditionalCellDOB">DOB</div>
            <div class="AdditionalCellRelationship">Relationship</div>
        </div>
    </HeaderTemplate>

    <ItemTemplate>
       <div class="AdditionalRow">
            <div class="AdditionalInputTitle">
                <asp:DropDownList ID="AdTitle" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="Miss" Text="Miss"/>
                    <asp:ListItem Selected="False" Value="Ms" Text="Ms"/>
                    <asp:ListItem Selected="False" Value="Mrs" Text="Mrs"/>
                    <asp:ListItem Selected="False" Value="Mr" Text="Mr"/>
                    <asp:ListItem Selected="False" Value="Other" Text="Other"/>
                </asp:DropDownList>
            </div>

            <div class="AdditionalInputFirstName">
                <asp:TextBox ID="AdFirstName" runat="server"></asp:TextBox>
            </div>

            <div class="AdditionalInputLastName">
                <asp:TextBox ID="AdLastName" runat="server"></asp:TextBox>
            </div>

            <div class="AdditionalInputDOB">
                <asp:DropDownList ID="AdDOBDay" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="1" Text="1"/>
                    <asp:ListItem Selected="False" Value="2" Text="2"/>
                    <asp:ListItem Selected="False" Value="3" Text="3"/>
                    <asp:ListItem Selected="False" Value="4" Text="4"/>
                    <asp:ListItem Selected="False" Value="5" Text="5"/>
                    <asp:ListItem Selected="False" Value="6" Text="6"/>
                    <asp:ListItem Selected="False" Value="7" Text="7"/>
                    <asp:ListItem Selected="False" Value="8" Text="8"/>
                    <asp:ListItem Selected="False" Value="9" Text="9"/>
                    <asp:ListItem Selected="False" Value="10" Text="10"/>
                    <asp:ListItem Selected="False" Value="11" Text="11"/>
                    <asp:ListItem Selected="False" Value="12" Text="12"/>
                    <asp:ListItem Selected="False" Value="13" Text="13"/>
                    <asp:ListItem Selected="False" Value="14" Text="14"/>
                    <asp:ListItem Selected="False" Value="15" Text="15"/>
                    <asp:ListItem Selected="False" Value="16" Text="16"/>
                    <asp:ListItem Selected="False" Value="17" Text="17"/>
                    <asp:ListItem Selected="False" Value="18" Text="18"/>
                    <asp:ListItem Selected="False" Value="19" Text="19"/>
                    <asp:ListItem Selected="False" Value="20" Text="20"/>
                    <asp:ListItem Selected="False" Value="21" Text="21"/>
                    <asp:ListItem Selected="False" Value="22" Text="22"/>
                    <asp:ListItem Selected="False" Value="23" Text="23"/>
                    <asp:ListItem Selected="False" Value="24" Text="24"/>
                    <asp:ListItem Selected="False" Value="25" Text="25"/>
                    <asp:ListItem Selected="False" Value="26" Text="26"/>
                    <asp:ListItem Selected="False" Value="27" Text="27"/>
                    <asp:ListItem Selected="False" Value="28" Text="28"/>
                    <asp:ListItem Selected="False" Value="29" Text="29"/>
                    <asp:ListItem Selected="False" Value="30" Text="30"/>
                    <asp:ListItem Selected="False" Value="31" Text="31"/>
                </asp:DropDownList>

                <asp:DropDownList ID="AdDOBMonth" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="1" Text="January"/>
                    <asp:ListItem Selected="False" Value="2" Text="Febuary"/>
                    <asp:ListItem Selected="False" Value="3" Text="March"/>
                    <asp:ListItem Selected="False" Value="4" Text="April"/>
                    <asp:ListItem Selected="False" Value="5" Text="May"/>
                    <asp:ListItem Selected="False" Value="6" Text="June"/>
                    <asp:ListItem Selected="False" Value="7" Text="July"/>
                    <asp:ListItem Selected="False" Value="8" Text="August"/>
                    <asp:ListItem Selected="False" Value="9" Text="September"/>
                    <asp:ListItem Selected="False" Value="10" Text="October"/>
                    <asp:ListItem Selected="False" Value="11" Text="November"/>
                    <asp:ListItem Selected="False" Value="12" Text="December"/>
                </asp:DropDownList>

                <asp:DropDownList ID="AdDOBYear" runat="server">
                </asp:DropDownList>

                <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2"
                                           Category="AdDOBYear"
                                           LoadingText=""
                                           ServicePath="TravelWebService.asmx"
                                           ServiceMethod="GetYears"
                                           PromptText=""
                                           TargetControlID="AdDOBYear"
                                           runat="server">
                </ajaxToolkit:CascadingDropDown>
            </div>

            <div class="AdditionalInputRelationship">
                <asp:DropDownList ID="AdRelationship" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="Partner" Text="Partner"/>
                    <asp:ListItem Selected="False" Value="Child" Text="Child"/>
                    <asp:ListItem Selected="False" Value="Unrelated" Text="Unrelated"/>
                </asp:DropDownList>
            </div>
        </div>
   </ItemTemplate>
</asp:Repeater>

I've got a form that has to be a repeater on a webpage. I have a number parameter that tells me how many additional customer details are to be added. In this page I have a repeater control that needs to repeat items a set number of times. For each item there is a set of input boxes that needs an id appended to it. All I need to bind is a number for each additional input box ie <% #id %>. I dont know how to set up simple databind without a specific datasource, but just build one in a loop.

<asp:Repeater ID="myRepeater" runat="server"> 
    <HeaderTemplate>  
       <div class="AdditionalRowTitle">
            <div class="AdditionalCellTitle">Title</div>
            <div class="AdditionalCellFirstName">First Name</div>
            <div class="AdditionalCellLastName">Last Name</div>
            <div class="AdditionalCellDOB">DOB</div>
            <div class="AdditionalCellRelationship">Relationship</div>
        </div>
    </HeaderTemplate>

    <ItemTemplate>
       <div class="AdditionalRow">
            <div class="AdditionalInputTitle">
                <asp:DropDownList ID="AdTitle" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="Miss" Text="Miss"/>
                    <asp:ListItem Selected="False" Value="Ms" Text="Ms"/>
                    <asp:ListItem Selected="False" Value="Mrs" Text="Mrs"/>
                    <asp:ListItem Selected="False" Value="Mr" Text="Mr"/>
                    <asp:ListItem Selected="False" Value="Other" Text="Other"/>
                </asp:DropDownList>
            </div>

            <div class="AdditionalInputFirstName">
                <asp:TextBox ID="AdFirstName" runat="server"></asp:TextBox>
            </div>

            <div class="AdditionalInputLastName">
                <asp:TextBox ID="AdLastName" runat="server"></asp:TextBox>
            </div>

            <div class="AdditionalInputDOB">
                <asp:DropDownList ID="AdDOBDay" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="1" Text="1"/>
                    <asp:ListItem Selected="False" Value="2" Text="2"/>
                    <asp:ListItem Selected="False" Value="3" Text="3"/>
                    <asp:ListItem Selected="False" Value="4" Text="4"/>
                    <asp:ListItem Selected="False" Value="5" Text="5"/>
                    <asp:ListItem Selected="False" Value="6" Text="6"/>
                    <asp:ListItem Selected="False" Value="7" Text="7"/>
                    <asp:ListItem Selected="False" Value="8" Text="8"/>
                    <asp:ListItem Selected="False" Value="9" Text="9"/>
                    <asp:ListItem Selected="False" Value="10" Text="10"/>
                    <asp:ListItem Selected="False" Value="11" Text="11"/>
                    <asp:ListItem Selected="False" Value="12" Text="12"/>
                    <asp:ListItem Selected="False" Value="13" Text="13"/>
                    <asp:ListItem Selected="False" Value="14" Text="14"/>
                    <asp:ListItem Selected="False" Value="15" Text="15"/>
                    <asp:ListItem Selected="False" Value="16" Text="16"/>
                    <asp:ListItem Selected="False" Value="17" Text="17"/>
                    <asp:ListItem Selected="False" Value="18" Text="18"/>
                    <asp:ListItem Selected="False" Value="19" Text="19"/>
                    <asp:ListItem Selected="False" Value="20" Text="20"/>
                    <asp:ListItem Selected="False" Value="21" Text="21"/>
                    <asp:ListItem Selected="False" Value="22" Text="22"/>
                    <asp:ListItem Selected="False" Value="23" Text="23"/>
                    <asp:ListItem Selected="False" Value="24" Text="24"/>
                    <asp:ListItem Selected="False" Value="25" Text="25"/>
                    <asp:ListItem Selected="False" Value="26" Text="26"/>
                    <asp:ListItem Selected="False" Value="27" Text="27"/>
                    <asp:ListItem Selected="False" Value="28" Text="28"/>
                    <asp:ListItem Selected="False" Value="29" Text="29"/>
                    <asp:ListItem Selected="False" Value="30" Text="30"/>
                    <asp:ListItem Selected="False" Value="31" Text="31"/>
                </asp:DropDownList>

                <asp:DropDownList ID="AdDOBMonth" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="1" Text="January"/>
                    <asp:ListItem Selected="False" Value="2" Text="Febuary"/>
                    <asp:ListItem Selected="False" Value="3" Text="March"/>
                    <asp:ListItem Selected="False" Value="4" Text="April"/>
                    <asp:ListItem Selected="False" Value="5" Text="May"/>
                    <asp:ListItem Selected="False" Value="6" Text="June"/>
                    <asp:ListItem Selected="False" Value="7" Text="July"/>
                    <asp:ListItem Selected="False" Value="8" Text="August"/>
                    <asp:ListItem Selected="False" Value="9" Text="September"/>
                    <asp:ListItem Selected="False" Value="10" Text="October"/>
                    <asp:ListItem Selected="False" Value="11" Text="November"/>
                    <asp:ListItem Selected="False" Value="12" Text="December"/>
                </asp:DropDownList>

                <asp:DropDownList ID="AdDOBYear" runat="server">
                </asp:DropDownList>

                <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2"
                                           Category="AdDOBYear"
                                           LoadingText=""
                                           ServicePath="TravelWebService.asmx"
                                           ServiceMethod="GetYears"
                                           PromptText=""
                                           TargetControlID="AdDOBYear"
                                           runat="server">
                </ajaxToolkit:CascadingDropDown>
            </div>

            <div class="AdditionalInputRelationship">
                <asp:DropDownList ID="AdRelationship" runat="server">
                    <asp:ListItem Selected="True" Value="" Text=""/>
                    <asp:ListItem Selected="False" Value="Partner" Text="Partner"/>
                    <asp:ListItem Selected="False" Value="Child" Text="Child"/>
                    <asp:ListItem Selected="False" Value="Unrelated" Text="Unrelated"/>
                </asp:DropDownList>
            </div>
        </div>
   </ItemTemplate>
</asp:Repeater>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2024-07-28 08:02:12

这是重复这些项目的方法。 在页面加载事件中,添加以下内容:

Dim repeatTimes() As Integer = New Integer(){1, 2, 3}
myRepeater.DataSource = repeatTimes
myRepeater.DataBind()

重复器项目将按数组中的元素数量重复。 在本例中,有 3 个元素。 数组的实际内容并不重要,重要的是元素的数量。

编辑:我不太了解VB.NET,但我认为这应该可行

Sub Page_Load()
  Dim NumberToRepeat As Integer ''*Should come from the parameter
  If Not Page.IsPostBack Then
    Dim repeatTimes(NumberToRepeat) As Integer
    myRepeater.DataSource = repeatTimes
    myRepeater.DataBind()
  End If
End Sub

Here's a way to repeat the items. In your page load event, add the following:

Dim repeatTimes() As Integer = New Integer(){1, 2, 3}
myRepeater.DataSource = repeatTimes
myRepeater.DataBind()

The repeater items will be repeated by the number of elements in the Array. In this case, there are 3 elements. The actual contents of the array don't matter, just the number of elements.

EDIT: I don't know VB.NET that well, but I think this should work

Sub Page_Load()
  Dim NumberToRepeat As Integer ''*Should come from the parameter
  If Not Page.IsPostBack Then
    Dim repeatTimes(NumberToRepeat) As Integer
    myRepeater.DataSource = repeatTimes
    myRepeater.DataBind()
  End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文