在asp.net中使用转发器中的复选框

问题描述:

如何取消选中中继器数据控件中的所有复选框(而不是选中的复选框)?

how to uncheck all check boxes in repeater data control , other than the one being checked?

jQuery可以在客户端非常简单地做到这一点. br/>
但是,如果要在后面的代码中执行此操作:

jQuery could do that on the client side very simply.

However, if you want to do it in code behind:

<ItemTemplate >
    <asp:CheckBox ID="CheckBox1" runat="server"  AutoPostBack="True"

        oncheckedchanged="RepeaterCheckBox_CheckedChanged"/>







protected void RepeaterCheckBox_CheckedChanged(object sender, EventArgs e)
{
    // for each data row
    foreach (RepeaterItem RE in Repeater1.Controls)
    {
        // for each control in the data row
        foreach (Control C in RE.Controls)
        {
            CheckBox CB = C as CheckBox;

            if ((CB != null) && (CB != sender))
                CB.Checked = false;
        }
    }
}


虽然没有开箱即用的功能,但是可以使用一些javascript轻松完成,为此,有很多示例可用
There is nothing out of the box that will do this but it can be accomplished easily with some javascript, for which there are many examples available