c# - ASP.NET Repeater 控件复选框问题

标签 c# asp.net repeater

概述:单击转发器控件中第一个 CheckBox 的文本会单击最后一个。我知道为什么会这样; label 标签与元素 id chkMarkedForDeletion 的关联,当该标签被点击时,它会选择最后一个 CheckBox,因为所有 CheckBox 都有相同的 ID.. 该死的中继器控件!我想知道是否有任何方法可以避免这种情况?简单的方法是创建单独的标签并正确关联到每个 CheckBox,但这会破坏 CheckBox 的假定默认行为。

转发器代码:

<asp:Repeater ID="childNodesDataRepeater" runat="server">
    <ItemTemplate>
        <table style="width: 100%;" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td style="width: 200px;">
                    <asp:CheckBox ID="chkMarkedForDeletion" runat="server" EnableViewState="true" Text="Remove"
                        Checked='<%# DataBinder.Eval(Container.DataItem, "IsMarkedForDeletion") %>' />
                </td>
                <td>
                    &nbsp;
                </td>
                <td style="width: 200px;">
                    <asp:CheckBox ID="chkHighImpactCause" runat="server" EnableViewState="true" Text="High Impact Cause"
                        Checked='<%# DataBinder.Eval(Container.DataItem, "IsHighPriority") %>' />
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:Label ID="header002" runat="server" Text="What caused this problem?" />
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:TextBox ID="txtProblemCausedBy" runat="server" EnableViewState="true" Width="100%"
                        Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' /><br />
                </td>
            </tr>
            <tr>
                <td colspan="3" style="height: 5px;">
                    <hr />
                    <asp:HiddenField ID="nodeIdentifier" runat="server" EnableViewState="true" Value='<%# DataBinder.Eval(Container.DataItem, "AnalysisID") %>' />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:Repeater>

为 CheckBox 生成的 HTML 代码:

<INPUT id=chkMarkedForDeletion type=checkbox name=TabContainer$tabProblemResolution$frmProblemResolution1$childNodesDataRepeater$ctl00$chkMarkedForDeletion>
<LABEL for=chkMarkedForDeletion>Remove</LABEL>
...
...
<INPUT id=chkMarkedForDeletion type=checkbox name=TabContainer$tabProblemResolution$frmProblemResolution1$childNodesDataRepeater$ctl02$chkMarkedForDeletion>
<LABEL for=chkMarkedForDeletion>Remove</LABEL>

问题: Repeater Issue ScreenShot

谢谢, 阿比

最佳答案

确保 ClientIDMode中继器上的未设置为“静态”。

此设置可从父级继承,一直到 web.config。因此,如果您必须在中继器上显式设置 ClientIDMode,则意味着某些父级将默认值(可预测)覆盖为“静态”。

关于c# - ASP.NET Repeater 控件复选框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14486704/

相关文章:

asp.net - 如何将 jquery UI 按钮应用到 asp :Button

c# - 如何修复 asp.net 应用程序中的 MAC 错误?

apache-flex - Flex 3 : Error: Repeater is not executing. .. 我知道为什么,但我不知道如何修复它

c# - 访问中继器中的对象数据

c# - 如何使用 EF Core 选择列表中不在表中的值?

c# - 使用 SSH.NET 从 Ubuntu 服务器上的文件中删除行

c# - 如果 EF Core 中的模型在没有迁移的情况下发生变化,则删除数据库

c# - Specflow BeforeTestRun 记录

asp.net - 在中继器 asp.net 中调用函数

c# - 如何让 Chrome Native Messaging 收听应用程序?