【问题标题】:Check a checkbox when the other is checked in gridview在gridview中选中另一个时选中一个复选框
【发布时间】:2016-11-23 02:34:09
【问题描述】:

目前我在 gridview 中有 3 个复选框,分别是批准、访问和编辑。我想要实现的是当我检查编辑列时,访问列也会自动检查。有没有办法解决这个问题?我浏览了很多互联网资源,但仍然无法做到。请帮帮我..

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowSorting="True" BorderStyle="Solid" Font-Names="Tahoma" Font-Size="11pt" HorizontalAlign="Center" Width="65%">
                    <Columns>
                        <asp:BoundField DataField="Module" HeaderText="Module" SortExpression="Module" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:TemplateField HeaderText="Approval">
                            <ItemTemplate>
                                <asp:CheckBox ID="CBApproval" runat="server" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Access">
                            <ItemTemplate>
                                <asp:CheckBox ID="CBAccess" runat="server" AutoPostBack="False" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Edit">
                            <ItemTemplate>
                                <asp:CheckBox ID="CBEdit" runat="server" AutoPostBack="True"/> 
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>

                    </Columns>
                    <HeaderStyle BackColor="#FFCC00" BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" />
                </asp:GridView>

【问题讨论】:

  • 将它们绑定到视图模型中的同一个属性。
  • @CodingYoshi 你能用更清晰的形式解释一下吗?因为我真的不明白你的意思。谢谢。

标签: c# asp.net gridview checkbox


【解决方案1】:

Sinc 编辑复选框回发,您可以从代码隐藏中设置访问复选框的值。在单击时添加新事件以编辑复选框并为访问的复选框设置新值。检查

【讨论】:

    猜你喜欢
    • 2018-04-15
    • 2021-12-23
    • 1970-01-01
    • 2023-03-13
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多