我正在使用DevExpress Asp.Net Controls,在GridView EditTempalte中必须添加复选框,必须绑定复选框检查并取消选中数据库列属性,并在新项目插入默认未选中。
这是我的代码。
<dx:ASPxGridView ID="ASPxGridView3" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3"
KeyFieldName="UniqueID" Theme="Default">
<SettingsSearchPanel Visible="True" />
<Columns>
<dx:GridViewCommandColumn ShowDeleteButton="True" ShowEditButton="True" ShowInCustomizationForm="True"
ShowNewButtonInHeader="True" VisibleIndex="0">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="UniqueID" ReadOnly="True" ShowInCustomizationForm="True"
Visible="False" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ResourceID" ShowInCustomizationForm="True" Visible="False"
VisibleIndex="2" ReadOnly="True">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ResourceName" ShowInCustomizationForm="True" VisibleIndex="3">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Color" ShowInCustomizationForm="True" Visible="False" VisibleIndex="4">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CustomField1" ShowInCustomizationForm="True" Visible="False" VisibleIndex="5">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="category_ClientID" ShowInCustomizationForm="True"
VisibleIndex="6" Visible="False">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="IsAvailable" PropertiesTextEdit-NullDisplayText="true"
ShowInCustomizationForm="True" VisibleIndex="7">
**<EditItemTemplate>
<dx:ASPxCheckBox ID="chkIsAvailableEdit" runat="server" Checked="true" Style="margin-left: 18px"
CheckState="Checked" Cursor="pointer" EnableDefaultAppearance="False"
EnableTheming="False">
<CheckedImage Height="26px" Url="~/images/switchon.png" Width="70px">
</CheckedImage>
<UncheckedImage Height="26px" Url="~/images/switchoff.png" Width="70px">
</UncheckedImage>
<GrayedImage Url="~/images/switchoff.png">
</GrayedImage>
</dx:ASPxCheckBox>
</EditItemTemplate>**
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:NCompassWebsiteConnectionString %>"
DeleteCommand="DELETE FROM [SchResources] WHERE [UniqueID] = @UniqueID"
InsertCommand="INSERT INTO [SchResources] ([ResourceID], [ResourceName], [Color], [CustomField1], [category_ClientID],
[IsAvailable]) VALUES (@ResourceID, @ResourceName, @Color, @CustomField1, @category_ClientID, @IsAvailable)"
SelectCommand="SELECT * FROM [SchResources] WHERE ([category_ClientID] = @category_ClientID)"
UpdateCommand="UPDATE [SchResources] SET [ResourceID] = @ResourceID, [ResourceName] = @ResourceName, [Color] = @Color,
[CustomField1] = @CustomField1, [category_ClientID] = @category_ClientID, [IsAvailable] = @IsAvailable WHERE [UniqueID] = @UniqueID">
<DeleteParameters>
<asp:Parameter Name="UniqueID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ResourceID" Type="Int32" />
<asp:Parameter Name="ResourceName" Type="String" />
<asp:Parameter Name="Color" Type="Int32" />
<asp:Parameter Name="CustomField1" Type="String" />
<asp:SessionParameter Name="category_ClientID" SessionField="ClientID" Type="String" />
<asp:Parameter Name="IsAvailable" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="category_ClientID" SessionField="ClientID" Type="String" />
<%--<asp:Parameter DefaultValue="62" Name="category_ClientID" Type="String" />--%>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ResourceID" Type="Int32" />
<asp:Parameter Name="ResourceName" Type="String" />
<asp:Parameter Name="Color" Type="Int32" />
<asp:Parameter Name="CustomField1" Type="String" />
<asp:SessionParameter Name="category_ClientID" SessionField="ClientID" Type="String" />
<asp:Parameter Name="IsAvailable" Type="String" />
<asp:Parameter Name="UniqueID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
答案 0 :(得分:1)
只需使用内置的 GridViewDataCheckColumn (专门用于显示/编辑布尔值)而不是 GridViewDataTextColumn (默认值):
<%--
<dx:GridViewDataTextColumn FieldName="IsAvailable">
</dx:GridViewDataTextColumn
--%>
<dx:GridViewDataCheckColumn FieldName="IsAvailable">
</dx:GridViewDataCheckColumn
检查this演示。
或者,使用标准的双向绑定表达式(Bind方法)将ASPxCheckBox与必要的行的FieldName绑定:
<dx:GridViewDataTextColumn FieldName="IsAvailable">
<EditItemTemplate>
<dx:ASPxCheckBox ID="chkIsAvailableEdit" ... Value='<%#Bind("IsAvailable")'>
</dx:ASPxCheckBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
检查this演示。