该错误(在我的网页中):(不包含' GVTable1_RowDeleting'的定义,并且没有扩展方法' GVTable1_Row删除'接受类型'的第一个参数ASP.desktopmodules_friends1_friends1_friends_ascx'可以找到(您是否缺少using指令或程序集引用?)) 但我的代码是: 在ascx中:
<asp:TableRow><asp:TableCell>
<asp:GridView ID="GVTable1" runat="server" AutoGenerateColumns ="false" OnRowCommand="GVTable1_RowCommand" OnRowDeleting="GVTable1_RowDeleting" OnRowEditing ="GVTable1_RowEditing">
<columns>
<asp:TemplateField HeaderText="No.">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="name"/>
<asp:BoundField DataField="famil" HeaderText="famil"/>
<asp:BoundField DataField="field" HeaderText="field"/>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" CausesValidation="false" CommandName="Delete" Text="Delete" CommandArgument='<%# Eval("id") %>' onClientClick="return confirm('Are you sure?')" />
<asp:Button ID="btnEdit" runat="server" CausesValidation="false" CommandName="Edit" Text="Edit" CommandArgument='<%# Eval("id") %>' />
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
</asp:TableCell>
</asp:TableRow>
现在我的代码用于在cs中重新接收参数和删除:
protected void GVTable1_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "Delete":
Int32 rn = Convert.ToInt32(e.CommandArgument);
string connstring = "Data Source=VAVAN-PC\\SQL2014;Initial Catalog=db1;Persist Security Info=True;User------;
string queryDel = "delete from [db1].[dbo].[tbl1] where [db1].[dbo].[tbl1].id = @id;";
SqlConnection conn = new SqlConnection(connstring);
SqlCommand cmd = new SqlCommand(queryDel, conn);
conn.Open();
cmd.Parameters.AddWithValue("@id", rn);
cmd.ExecuteNonQuery();
conn.Close();
Fill_grid();
break;
答案 0 :(得分:0)
您发布了方法GVTable1_RowCommand
的代码。
该错误与另一种方法有关:GVTable1_RowDeleting
。
您应该检查方法GVTable1_RowDeleting
是否存在
答案 1 :(得分:0)
您必须在aspx页面而不是ascx中编写gridview事件(rowdeleting)。