【问题标题】:How to enable a checkbox in Gridview only when it's in the Edit mode?仅当处于编辑模式时,如何在 Gridview 中启用复选框?
【发布时间】:2016-01-28 01:33:54
【问题描述】:

这就是我目前拥有我的复选框列的方式:

          <asp:TemplateField HeaderText="Hide/Show" ItemStyle-HorizontalAlign="Center" SortExpression="Hide_Show">
                <ItemTemplate>
                    <asp:CheckBox ID="HideShowChk" runat="server" Checked='<%# Bind("Hide_Show") %>' />
                </ItemTemplate>
            </asp:TemplateField>

我的代码中没有代码,因为没有必要。基本上,用户可以选中或取消选中它,但它不会反映在数据库中,除非我真正进入编辑模式,选中或取消选中它,然后点击更新,以便更改反映在数据库中。

有没有办法让复选框在不处于编辑模式时被“禁用”或类似的东西?

【问题讨论】:

    标签: asp.net gridview checkbox


    【解决方案1】:

    您必须使用 edititemtemplate 在编辑模式下启用它

     <edititemtemplate>
     <asp:CheckBox ID="HideShowChk" runat="server" Checked='<%# Bind("Hide_Show") %>' />
     </edititemtemplate>
    

    如果您仍想使用 ItemTemplate 中的复选框,请使用 CSS 或 jQuery 将其禁用。

    【讨论】:

    • 成功了,谢谢。但是,该列现在什么也不显示。想法?
    • 也把它放在 中,并使其禁用类似
    • 有了这个在 asp:CheckBox 上的特技, 就是你所需要的:Enabled=''
    猜你喜欢
    • 1970-01-01
    • 2021-09-22
    • 2023-04-02
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 2014-09-21
    相关资源
    最近更新 更多