Gridview vith 复选框 - 当选中某些复选框时使按钮处于非活动状态
我有一个 Gridview 绑定了 SQL 表中的一些数据。在 GV 的第一列中我有复选框。是否可以根据选中的复选框来启用/禁用按钮?
为了更好地理解这里有一个例子;
在 GV 中,我们有第一列 cbox,第二列是 ID,第三列是类别。
<asp:GridView ID="MyGV" runat="server" AutoGenerateColumns="False" DataKeyNames="ID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="MyCBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="category" HeaderText="Category" SortExpression="category" />
</Columns>
</asp:GridView>
我们有两个按钮(Btn1 和 Btn2)
<asp:Button ID="Btn1" runat="server" Text="btn1" OnClick="Btn1_Click" />
<asp:Button ID="Btn2" runat="server" Text="btn2" OnClick="Btn2_Click" />
现在...假设我们有 2 个类别(Cat1 和 Cat2)。当我们选择一个复选框并且该行中的类别值为 Cat1 时,我们启用了 Btn1 并禁用了 Btn2;
Btn1.Enabled = true;
Btn2.Enabled = false;
这可以做到吗?如何?
I have a Gridview binded with some data from SQL table. In the first column of GV I have CheckBoxes. Is it possible, to enable/disable button depending on which checkboxes were checked?
For better understanding here is an example;
In GV we have first column of cboxes, second column is ID and third column is Category.
<asp:GridView ID="MyGV" runat="server" AutoGenerateColumns="False" DataKeyNames="ID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="MyCBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="category" HeaderText="Category" SortExpression="category" />
</Columns>
</asp:GridView>
We have two Buttons (Btn1 and Btn2)
<asp:Button ID="Btn1" runat="server" Text="btn1" OnClick="Btn1_Click" />
<asp:Button ID="Btn2" runat="server" Text="btn2" OnClick="Btn2_Click" />
Now...Let's say we have 2 categories (Cat1 and Cat2). When we select a checkbox and in that row Category value is Cat1, we have Btn1 enabled and Btn2 disabled;
Btn1.Enabled = true;
Btn2.Enabled = false;
Can this be done? How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您只有两个类别
复选框的代码隐藏事件,请尝试此操作
Try this assuming that you have only two categories
Code behind event for the checkbox
按钮是网格的一部分吗?
Are the buttons part of the grid?