我已经在gridview控件中添加了GridViewDataComboBoxColumn并列出项目,我想更新它,当我点击编辑并从GridViewDataComboBoxColumn中选择项目并点击更新按钮列表项目没有更新我是设计师而我不知道c#请提供解决方案,从设计师/图形中做到这一点。
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" Width="100%" DataSourceID="SqlDataSource1" KeyFieldName="ID" EnableTheming="True" Theme="Office2010Blue">
<Columns>
<dx:GridViewCommandColumn ShowEditButton="True" VisibleIndex="0">
<HeaderTemplate>
Click "Edit" button below for Update
</HeaderTemplate>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ID" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProjectName" VisibleIndex="2" ReadOnly="True">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Menu" VisibleIndex="3" ReadOnly="True">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ErrorDescription" VisibleIndex="5">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="DeveloperRemarks" VisibleIndex="6" ReadOnly="True">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ReportedBy" VisibleIndex="7" ReadOnly="True">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="FixedBy" VisibleIndex="8" ReadOnly="True">
</dx:GridViewDataTextColumn>
<dx:GridViewDataComboBoxColumn FieldName="ErrorType" VisibleIndex="4">
<PropertiesComboBox DropDownStyle="DropDownList">
<Items>
<dx:ListEditItem Text="ScreenValidation" />
<dx:ListEditItem Text="Validation" />
<dx:ListEditItem Text="Syntax" />
<dx:ListEditItem Text="Logical" />
<dx:ListEditItem Text="Layout" />
</Items>
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataComboBoxColumn FieldName="Status" VisibleIndex="9">
<PropertiesComboBox DropDownStyle="DropDownList">
<Items>
<dx:ListEditItem Text="Bug"/>
<dx:ListEditItem Text="Fixed"/>
<dx:ListEditItem Text="Closed" />
</Items>
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
</Columns>
<SettingsDataSecurity AllowDelete="False" AllowInsert="False" />
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ErrorReportDBConnectionString %>" SelectCommand="SELECT * FROM [BugsReport]" UpdateCommand="UPDATE [BugsReport] SET [ProjectName] = @ProjectName, [Menu] = @Menu, [ErrorType] = @ErrorType, [ErrorDescription] = @ErrorDescription, [DeveloperRemarks] = @DeveloperRemarks, [ReportedBy] = @ReportedBy, [FixedBy] = @FixedBy, [Status] = @Status WHERE [ID] = @ID">
<UpdateParameters>
<asp:Parameter Name="ProjectName" Type="String" />
<asp:Parameter Name="Menu" Type="String" />
<asp:Parameter Name="ErrorType" Type="String" />
<asp:Parameter Name="ErrorDescription" Type="String" />
<asp:Parameter Name="DeveloperRemarks" Type="String" />
<asp:Parameter Name="ReportedBy" Type="String" />
<asp:Parameter Name="FixedBy" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="Click Here To Insert New Record" Theme="Office2003Blue">
</dx:ASPxButton>
答案 0 :(得分:0)
要支持更新数据库中的数据,必须在SqlDataSource中声明适当的UpdateCommand。例如:
UpdateCommand="UPDATE [BugsReport] SET [ErrorType] = @ErrorType WHERE ID = @ID
本博客提供了有关示例的SqlDataSource函数的完整说明:Inserting, Updating, and Deleting Data with the SqlDataSource。
当绑定到SqlDataSource组件时,ASPxGridView可以自动发出UPDATE查询。要使此功能正常工作,必须指定KeyFieldName属性值。它应该指向数据源中的标识列。