由于有问题的数据源是join语句的结果,我必须指定delete命令。我试着做以下但是没有用。
<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页面中执行删除过程。