简体   繁体   English

如何获取直放站内的复选框ID

[英]How to get the Id of Checkbox which is inside a Repeater

I have a repeater inside which i put a Checkbox and above rapeater there is a HTML checkbox which is used to Check/Uncheck a Checkbox which is inside repeater using client side javascript. 我在其中放置了一个复选框的转发器内,在rapeater上方有一个HTML复选框,该复选框用于使用客户端JavaScript在转发器内部选中/取消选中一个复选框。 Here is my Code: JavaScript for Check/Uncheck: 这是我的代码:选中/取消选中的JavaScript:

<script type="text/javascript">
    function selectAll() {

        for (i = 0; i < document.all.length; i++) {
            alert("Working");
            if (document.all[i].type == 'checkbox') {
                if (document.getElementById(cbSelectAll).Checked = true) {
                    //document.all[i].Checked = false;
                } else {
                    document.all[i].Checked = true;
                }
            }
        }
    }
</script>

HTML Code for Repeater: 转发器的HTML代码:

<div id="hdPropertyList" runat="server">
    <table border="0" cellpadding="0" cellspacing="0" class="navigation" width="100%">
        <tr>
            <td>
                <input type="checkbox" id="cbSelectAll" onchange="selectAll()" />
                <asp:Button runat="server" ID="btnContactAll" Text="Contact All" />
            </td>
            <td id="tdOrderBy" runat="server">
            </td>
            <td>
                <asp:Label ID="lblPage" runat="server" CssClass="pageList"></asp:Label>
            </td>
        </tr>
    </table>
</div>
<div class="boxleft SearchFeaturedlist" style="display: none">
    <h2>
        Featured Properties</h2>
</div>
<asp:Repeater ID="rptPropertyList" runat="server" EnableViewState="false" OnItemDataBound="rptPropertyList_ItemDataBound"
    OnLoad="rptPropertyList_Load">
    <ItemTemplate>
        <table id="propertyTable" runat="server" enableviewstate="false">
            <tr id="tbrLabel" runat="server" enableviewstate="false">
                <td id="tbcLabel" colspan="3" runat="server" enableviewstate="false">
                </td>
            </tr>
            <tr id="tbrTitle" runat="server" enableviewstate="false">
                <td id="tbcTitle" runat="server" enableviewstate="false">
                    <asp:CheckBox ID="ChkSelect" runat="server" /><span id="spnSelect" runat="server"></span>
                </td>
            </tr>
        </table>
        <div id="divAds" runat="server" visible="false" enableviewstate="false" style="width: 100%;
            overflow: hidden">
        </div>
    </ItemTemplate>
</asp:Repeater>

Please help me in this regards. 请在这方面帮助我。 Thanks in Advance. 提前致谢。

The ID of the repeater will be available through it's ClientID property. 中继器的ID将通过其ClientID属性提供。

Really, you want to be asking whether you need this at all. 确实,您想问您是否根本需要这个。 Why not place the repeater inside a named div, and then simply find all input elements that have a type of checkbox that reside within it ( getElementsByTagName would help here ). 为什么不将转发器放置在一个命名的div中,然后简单地查找其中包含复选框类型的所有输入元素( getElementsByTagName在这里会有所帮助)。

With a decent js addon library, like mootools or jQuery, you'll be able to use CSS selectors, which will make your task even easier. 使用像mootools或jQuery这样的js插件库,您将能够使用CSS选择器,这将使您的任务更加轻松。

Here's mootools example :- 这是mootools示例:-

function selectAllOrNone() 
{
    var myNewValue = $('selectall').innerText == "All" ? "None" : "All";
    var myCheckers = $$('input[type=checkbox]');

    $('selectall').innerText = myNewValue;

    myCheckers.each(
        function(e) {
            e.checked = (myNewValue == "None");
        }
    );
}

I got the answer using Jquery. 我得到了使用jQuery的答案。 I used only the HTML checkbox to Check Uncheck all the checkbox on my Asp.net page. 我仅使用HTML复选框来选中“取消选中Asp.net页面上的所有复选框”。

<script type="text/javascript">
$(document).ready(function() {
    $('td.title_listing :checkbox').change(function() {
        $('#cbSelectAll').attr('checked', false);
    });
});
function CotactSelected() {
    var n = $("td.title_listing input:checked");
    alert(n.length);
    var s = "";
    n.each(function() {
        s += $(this).val() + ",";
    });
    window.location = "/D_ContactSeller.aspx?property=" + s;
    alert(s);
}

Thanks to "Paul Alan Tylor" for your guidance. 感谢“ Paul Alan Tylor”的指导。

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

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