0

I'm trying to write privilige group checkbox. Something like this

So far I made page where I put empty control made by me which looks like this

<fieldset>
  <legend><asp:CheckBox ID="GroupName" runat="server" TextAlign="Left" text="test" onclick="checkAll()"/></legend>
<span> <!--class="filterTableSpan"-->
<asp:Table ID="priviligeTable" runat="server" CssClass="groupTable">


</asp:Table>
</span>
</fieldset>

then I fill priviligeTable

CheckBox privilCheck = new CheckBox();
privilCheck.ID = this.ID + "_" + privName; //ID of group

TableCell tc = new TableCell();
tc.ID = this.ID + "_tc" + privName;
tc.Controls.Add(privilCheck);
TableRow tr = new TableRow();
tr.ID = this.ID + "_tr" + privName;
tr.Cells.Add(tc);
this.priviligeTable.Rows.Add(tr);

and now I'd like to make javascript for select all, unselect and mid state to Privilige Group Name checkbox, but I do not know how to access dynamic generated checkboxes. Furthermore I'm a newbie with javascript. I would be pleased if someone could show me a way to solve this problem or rather a direction which I should head to solve by my efforts this problem.

4

1 回答 1

0

这些角色是否来自数据库中的列表?如果是这样,我的直觉是避免使用并使用。Gridview 为您提供更多内置功能,包括使您能够随时随地创建所有复选框的模板。

但是,您正在做的事情也可以工作。

我建议使用jQuery——它会让你的生活更轻松,并确保你的代码可以在所有浏览器上运行。

然后你需要这样的东西。这将打开或关闭所有复选框。

function checkAll() {
    // Find all the checkboxes in the table
    var $checkboxes = $('table.groupTable input[type=checkbox]');

    if($(this).is(':checked')){
        // Check them
        $checkboxes.attr("checked","checked");
    } else {
        // Uncheck them
        $checkboxes.removeAttr("checked",);
    }
}

我认为应该这样做。不过,不确定您所说的“中间状态”是什么意思。他们要么被检查,要么不被检查。

不要忘记,在回发时,您需要重新创建所有复选框才能读取其内容。

于 2013-09-10T20:38:48.587 回答