简体   繁体   English

创建具有多个asp:Repeater TextBoxes的Bootstrap-Datepicker

[英]Creating Bootstrap-Datepicker with multiple asp:Repeater TextBoxes

I am creating form using an asp:Repeater, each object of the repeater has one textbox that will need it's own unique bootstrap-datepicker linked to it. 我正在使用asp:Repeater创建表单,该转发器的每个对象都有一个文本框,该文本框需要将其链接到它自己的唯一bootstrap-datepicker。 (the datepicker is a javascript addon to twitter-bootstrap 2.3.2 found here: http://www.eyecon.ro/bootstrap-datepicker -- Wanted to add that the link is safe, but there is no real need to view the page in regards to the question) (datepicker是twitter-bootstrap 2.3.2的javascript插件,可在此处找到: http ://www.eyecon.ro/bootstrap-datepicker-希望添加此链接是安全的,但实际上并不需要查看关于问题的页面)

My problem is that I am not able to use the asp.net clientid to correctly target the text boxes. 我的问题是我无法使用asp.net clientid正确定位文本框。

aspx code: aspx代码:

<asp:Repeater ID="repList" runat="server">
    <HeaderTemplate>
        <ul class="gridul">
            <li class="gridli userrole"><span class="short liheader">Jenz ID</span></li>
            <li class="gridli"><span class="long liheader">Name</span></li>
            <li class="gridli"><span class="short liheader">S/S/F</span></li>
            <li class="gridli"><span class="short liheader">Date</span></li>
            <li class="gridli"><span class="long liheader">Payment Type</span></li>
            <li class="gridli"><span class="mid liheader">Sent to B.O.</span></li>
        </ul>
    </HeaderTemplate>
    <ItemTemplate>
        <ul class="gridul">
            <li class="gridli userrole"><span class="short"><%# Eval("jenzabar_id") %></span></li>
            <li class="gridli"><span class="long"><%# Eval("first_name") %>&nbsp<%# Eval("last_name") %></span></li>
            <li class="gridli"><span class="short"><%# Eval("student_staff_faculty") %></span></li>
            <li class="gridli"><span class="short"><%# Eval("reservation_date") %></span></li>
            <li class="gridli"><span class="long"><asp:TextBox ID="PayType" runat="server" Text='<%# Eval("payment_type") %>' /></span></li>
            <li class="gridli"><span class="mid"><asp:TextBox ID="SentBo" runat="server" Text='<%# Eval("sent_to_bo") %>' /></span></li>
        </ul>
        <asp:HiddenField ID="hidJenz" runat="server" Value='<%# Eval("jenzabar_id") %>' />
        <asp:HiddenField ID="hidPayType" runat="server" Value='<%# Eval("payment_type") %>' />
        <asp:HiddenField ID="hidSentBo" runat="server" Value='<%# Eval("sent_to_bo") %>' />
    </ItemTemplate>
</asp:Repeater>

The textbox being targeted is: 定位的文本框是:

<asp:TextBox ID="SentBo" runat="server" Text='<%# Eval("sent_to_bo") %>' />

In my scripts.js I can target an individual textbox by viewing the aspx source and copying in the generated id such as "ctl00_MainContent_repList_ctl01_SentBo" but I cannot figure out how to use <%# SentBo.ClientID %> with the repeater. 在我的scripts.js中,我可以通过查看aspx源并复制生成的ID(例如“ ctl00_MainContent_repList_ctl01_SentBo”)来定位单个文本框,但是我不知道如何在转发器中使用<%#SentBo.ClientID%>。 It just doesn't work. 就是行不通。

Example: 例:

$(function () {
    $('ctl00_MainContent_repList_ctl01_SentBo').datepicker();
})

is successful 成功了

$(function () {
    $('<%#= SentBo.ClientID %>').datepicker();
})

is not 不是

Did more digging. 做了更多的挖掘。 Found the answer, finally. 终于找到答案了。

Replace: 更换:

$('ctl00_MainContent_repList_ctl01_SentBo').datepicker();

with: 有:

$(this).find("input[type=text][id*=SentBo]").datepicker();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM