在c#中,当我构建我的项目没有错误,但当我运行我的页面显示错误

本文关键字:我的 运行 错误 显示 项目 构建 有错误 | 更新日期: 2023-09-27 18:03:13

该错误是(在我的网页中):(不包含'GVTable1_RowDeleting'的定义,也没有扩展方法'GVTable1_RowDeleting'接受类型'ASP.desktopmodules_friends1_friends1_friends_ascx'的第一个参数可以找到(您是否缺少使用指令或汇编引用?)但我的代码是: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;

在c#中,当我构建我的项目没有错误,但当我运行我的页面显示错误

您将不得不在aspx页面而不是ascx中编写gridview事件(rowdeleting)。

您发布了方法GVTable1_RowCommand的代码。此错误与另一种方法GVTable1_RowDeleting有关。您应该检查方法GVTable1_RowDeleting是否存在