由于有问题的数据源是连接语句的结果,因此我必须指定删除命令。我尝试执行以下操作,但它不起作用。
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" DeleteMethod="GridView1_RowDeleting" SelectMethod="GetSubjectPrerequisites" TypeName="EnrolSystemCore.SubjectPrerequisitesDSTableAdapters.subjectsTableAdapter">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="32113" Name="subjectid" QueryStringField="subjectid" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="sj_id" DataSourceID="ObjectDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowSorting="True">
<Columns>
<asp:BoundField DataField="sj_id" HeaderText="sj_id" ReadOnly="True" SortExpression="sj_id" />
<asp:BoundField DataField="sj_name" HeaderText="sj_name" SortExpression="sj_name" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Delete" ShowHeader="True" Text="Delete" />
</Columns>
</asp:GridView>
并在 .cs 文件中创建了以下删除行的方法:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int subjectID = Convert.ToInt32(Request.QueryString["subjectID"]);
GridViewRow row = GridView1.SelectedRow;
int prerequisite1 = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
try
{
SubjectPrerequisites subjectPrerequisite1 = new SubjectPrerequisites();
subjectPrerequisite1.removePreRequisite(subjectID, prerequisite1);
}
catch (Exception)
{
}
}
但是每当我尝试删除一行时,都会出现以下错误:
ObjectDataSource“ObjectDataSource1”找不到具有参数的非泛型方法“GridView1_RowDeleting”:original_sj_id。
我应该如何解决这个问题?我研究了现有的解决方案,但他们在我不想要的 aspx 页面中执行删除过程。