asp.net复选框 [英] asp.net checkbox
问题描述
我有一个GridView在我的SQL数据库从表中拉回来的数据。我在我的数据库设置为BIT数据值的复选框字段。我需要能够以接受或拒绝采购订单,以从表中选择在asp.net中的行(仅一次)。
I have a gridview pulling back data from a table in my SQL database. I have a checkbox field in my database set to BIT data value. I need to be able to select a row from the table in asp.net (only one at a time) in order to accept or decline a purchase order.
到目前为止,我有以下的code
So far i have the following code
<asp:CheckBoxField DataField="CheckBox" HeaderText="Select" Visible="true" ReadOnly="false" />
这是刚刚拉了回来,列复选框都有一个复选框值的事实,而不是让我选择它。所有我看到的这个示威一直使用DataGrid视图,插入一个复选框到那里,不过,我似乎无法从我的数据库字段添加到这一点。
which is just pulling back the fact that the column "checkbox" has a checkbox value and not allowing me to select it. All of the demonstrations i have seen of this have been using the datagrid view and inserting a checkbox into there, however, i cant seem to add the fields from my database to this.
任何帮助的欢迎。
推荐答案
这是设计的,尽管是一个复选框字段,在GridView的行默认情况下编辑。我一直处理这个问题的方法是一个 模板列
:
This is by design as, despite being a checkbox field, the rows in a GridView are uneditable by default. The way I've always handled this is with a TemplateField
:
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkSelect" Checked='<%# Eval("Select") %>' />
</ItemTemplate>
</asp:TemplateField>
然后,如果你想一次只选择一个排,使用这样的事情(在的jQuery 1.6 )
var checkboxes = $('input[type="checkbox"][name$="chkSelect"]');
checkboxes.click(function() {
checkboxes.not(this).prop("checked", false);
});
这篇关于asp.net复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!