0

我有一个表单,其中有一个 CheckBox 和一个 gridview。当我取消选中复选框时,我希望禁用 Gridview 中的控件。这是我的gridview aspx:

                            <div id="gridVersion" runat="server">
                                <ac:GridViewWithPager ID="gdvwAllowedVersion" runat="server" UseCustomPager="True"
                                    AllowPaging="True" AutoGenerateColumns="False" Width="50%">
                                    <Columns>
                                        <asp:TemplateField ItemStyle-CssClass="centerdata">
                                            <ItemTemplate>
                                                <asp:RadioButton ID="rdblSelectedVersionList" runat="server" AutoPostBack="true" Checked='<%#Eval("IsSelected") %>'
                                                    EnableViewState="true" OnCheckedChanged="rdblSelectedVersionList_CheckedChanged" />
                                            </ItemTemplate>
                                            <HeaderStyle HorizontalAlign="Center" Width="2%"></HeaderStyle>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="IDEAlliance Version" HeaderStyle-Width="11%" HeaderStyle-HorizontalAlign="Left">
                                            <ItemTemplate>
                                                <asp:Label ID="lblVersion" runat="server" Text='<%# Eval("IdeAllianceVersion") %>' />
                                            </ItemTemplate>
                                            <HeaderStyle HorizontalAlign="Left" Width="11%"></HeaderStyle>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Restrict Import Of" ItemStyle-CssClass="centerdata"
                                            HeaderStyle-Width="2%" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="2%">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkCheckRestrictImport" runat="server" Checked='<%# Eval("RestrictedForImport")%>' />
                                            </ItemTemplate>
                                            <HeaderStyle HorizontalAlign="Center" Width="2%"></HeaderStyle>
                                            <ItemStyle HorizontalAlign="Center" Width="2%"></ItemStyle>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Restrict Upgrade To" ItemStyle-CssClass="centerdata"
                                            HeaderStyle-Width="2%" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="2%">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkCheckRestrictUpgrade" runat="server" Checked='<%# Eval("RestrictedForUpgrade")%>' />
                                            </ItemTemplate>
                                            <HeaderStyle HorizontalAlign="Center" Width="2%"></HeaderStyle>
                                            <ItemStyle HorizontalAlign="Center" Width="2%"></ItemStyle>
                                        </asp:TemplateField>
                                    </Columns>
                                </ac:GridViewWithPager>
                            </div>

我的 CheckBox 控件是这样的:

<asp:CheckBox ID="chkActivateSettings" runat="server" Text="Activate Restriction Settings.">
                                    </asp:CheckBox>

我已经编写了一个隐藏和显示此网格的 Jquery 代码。但现在我想要的是在取消选中复选框后禁用此网格中的控制。所以我想修改这段代码:

$(document).ready(function () {

    if ($('#<%=chkActivateSettings.ClientID %>').is(":checked")) {
        //show the hidden div
        $('#<%=gridVersion.ClientID %>').show("fast");
    }
    else {
        //otherwise, hide it
        $('#<%=gridVersion.ClientID %>').hide("fast");
    }
    // Add onclick handler to checkbox w/id checkme
    $('#<%=chkActivateSettings.ClientID %>').click(function () {

        // If checked
        if ($('#<%=chkActivateSettings.ClientID %>').is(":checked")) {
            //show the hidden div
            $('#<%=gridVersion.ClientID %>').Ena("fast");
        }
        else {
            //otherwise, hide it
            $('#<%=gridVersion.ClientID %>').hide("fast");
        }
    });

});

期待您平时的合作。

4

1 回答 1

0

尝试这个:

1) 添加 Enabled="True" 到 gridview 标记:

<ac:GridViewWithPager ID="gdvwAllowedVersion" runat="server" Enabled="True" UseCustomPager="True" AllowPaging="True" AutoGenerateColumns="False" Width="50%">

2)使用Jquery的DOM操作方法attr(key, value)来启用/禁用gridview:

$(document).ready(function () {

    // Add onclick handler to checkbox w/id checkme
    $('#<%=chkActivateSettings.ClientID %>').click(function () {

        // If checked
        if ($('#<%=chkActivateSettings.ClientID %>').is(":checked")) {
            //show the hidden div
            $('#<%=gdvwAllowedVersion.ClientID %>').attr("disabled", false);
        }
        else {
            //otherwise, hide it
            $('#<%=gdvwAllowedVersion.ClientID %>').attr("disabled", true);
        }
    });

});
于 2012-04-18T11:33:49.690 回答