通过ObjectDataSource使用TableAdapters的Asp.Net Gridview,删除不起作用

时间:2018-09-14 04:42:44

标签: asp.net

所以我有这个问题,我使用ObjectDataSource将数据绑定到Gridview,我使用了TableAdapter向导来设置查询(因此使用了DataSet),绑定没有问题,但是delete命令不是在工作中,我已经在TableAdapter中设置了Delete方法的参数,ObjectDataSource,并在gridview中设置了Delete命令的表达式。 (不过,我什至不确定自己的操作是否正确,我只是遵循教程,而这就是我最终得到的结果。)

这是数据集中的数据表

enter image description here

TableAdapter Select查询(我要联接三个表)

enter image description here

删除查询(我已经设置了参数)

enter image description here

在页面中,gridview代码

<asp:GridView ID="gv_inventory" CssClass="table-sm small" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="Inventory" Width="100%" ShowFooter="True">
                                    <Columns>
                                        <asp:CommandField ShowDeleteButton="True" SortExpression="InventoryID" />
                                        <asp:BoundField DataField="mat_Name" HeaderText="Material" SortExpression="mat_Name" />
                                        <asp:BoundField DataField="mat_Unit" HeaderText="Unit" SortExpression="mat_Unit" />
                                        <asp:BoundField DataField="Quantity" HeaderText="Qty" SortExpression="Quantity" />
                                        <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" DataFormatString="{0:c}" />
                                        <asp:BoundField DataField="CompanyName" HeaderText="Supplier" SortExpression="CompanyName" Visible="False" />
                                        <asp:BoundField DataField="DatePurchased" HeaderText="Purchased" SortExpression="DatePurchased" Visible="False" />
                                        <asp:BoundField DataField="DateEncoded" HeaderText="DateEncoded" SortExpression="DateEncoded" Visible="False" />
                                        <asp:BoundField DataField="Total" HeaderText="TOTAL" SortExpression="Total" DataFormatString="{0:c}" ReadOnly="True" />
                                        <asp:BoundField DataField="ProjectID" HeaderText="ProjectID" SortExpression="ProjectID" Visible="False" />
                                    </Columns>

                                </asp:GridView>

和ObjectDataSource

<asp:ObjectDataSource ID="Inventory" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="Budgetary_Allocation.DataSetTableAdapters.InventoryAllocationDatasetTableAdapter" DeleteMethod="DeleteCustomMethod">
                                    <DeleteParameters>
                                        <asp:Parameter Name="InventoryID" Type="Int32" />
                                    </DeleteParameters>
                                    <SelectParameters>
                                        <asp:QueryStringParameter DefaultValue="0" Name="ProjectID" QueryStringField="id" Type="Int32" />
                                    </SelectParameters>
                                </asp:ObjectDataSource>

0 个答案:

没有答案