How to fix CS1061 error for a GridView event that is defined

Bradley, Drew Alexander 0 Reputation points
2023-05-08T23:42:00.5866667+00:00

Every time I run my project I receive this error:

Server Error in '/S23BradleyD' Application.


Compilation Error

__Description:__An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

__Compiler Error Message:__CS1061: 'user_profile_aspx' does not contain a definition for '_people_RowDeleted' and no accessible extension method '_people_RowDeleted' accepting a first argument of type 'user_profile_aspx' could be found (are you missing a using directive or an assembly reference?)

Here is my aspx code for the gridview:

<asp:GridView ID="_people" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="personID" DataSourceID="SQLDataPerson" ForeColor="#333333" PageSize="50" HorizontalAlign="Center" OnSelectedIndexChanged="__people_SelectedIndexChanged" OnRowDeleted="_people_RowDeleted" OnRowUpdated="_people_RowUpdated">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:CommandField ShowEditButton="True">
            <ItemStyle ForeColor="Blue" Width="30px" />
            </asp:CommandField>
            <asp:TemplateField ShowHeader="False" Visible="False">
                <EditItemTemplate>
                    &nbsp;
                </EditItemTemplate>
                <ItemStyle ForeColor="#3399FF" />
            </asp:TemplateField>
            <asp:BoundField DataField="personID" HeaderText="personID" InsertVisible="False" ReadOnly="True" SortExpression="personID" Visible="False" />

            <asp:TemplateField HeaderText="First Name" SortExpression="firstName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("firstName") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="TextBox1" CssClass="errored" Display="Dynamic" ErrorMessage="*Required"></asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("firstName") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle CssClass="gridPadding" />
                <ItemStyle CssClass="gridPadding" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Last Name" SortExpression="lastName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("lastName") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="TextBox2" CssClass="errored" Display="Dynamic" ErrorMessage="*Required"></asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("lastName") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle CssClass="gridPadding" />
                <ItemStyle CssClass="gridPadding" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Email" SortExpression="email">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("email") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="TextBox3" CssClass="errored" Display="Dynamic" ErrorMessage="*Required"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox3" CssClass="errored" Display="Dynamic" ErrorMessage="*Invalid Email" ValidationExpression="\S+@\S+\.\S{2,3}"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("email") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle CssClass="gridPadding" VerticalAlign="Middle" />
                <ItemStyle CssClass="gridPadding" />
            </asp:TemplateField>

            <asp:BoundField HeaderText="Role" ReadOnly="True" DataField="roleDescription" />

            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete" ForeColor="Red" OnClientClick="return confirm('Are you sure you want to delete this person?')" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
                <ItemStyle Width="50px" />
            </asp:TemplateField>


            </Columns>


        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>

And here are my event handlers for the code behind file:

protected void _people_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            this._message.Text = "Person was Deleted";
        }

        protected void _people_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
            this._message.Text = "Person was Updated";
        }

I have been trying to resolve this for hours and have looked everywhere online that I can imagine to look and I don't see anyone with my same problem. Any help would be great!

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
Developer technologies | ASP.NET | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Albert Kallal 5,591 Reputation points
    2023-05-09T01:47:19.5233333+00:00

    Gee, first up, it always better to break into lines, so you can read what you have for the gridview.

    you have this:

         <asp:GridView ID="_people" runat="server" AllowPaging="True" 
             AllowSorting="True" 
             AutoGenerateColumns="False" CellPadding="4" 
             DataKeyNames="personID" 
             DataSourceID="SQLDataPerson" ForeColor="#333333" PageSize="50" 
             HorizontalAlign="Center" 
             OnSelectedIndexChanged="__people_SelectedIndexChanged" 
             OnRowDeleted="_people_RowDeleted" 
             OnRowUpdated="_people_RowUpdated">
    
    

    Looking at above, you even have 2 "__" for the selected index changed. (that's not all that great".

    I suggest you name the gv without the underscore.

    So, do this:

    fixgv

    At least now, we don't have potential "mix up" of _ or __ (2 of them). They are rather hard to read, or see.

    So, you will then have to cut+paste your existing code to the "new" events, and then delete the old ones.

    There (hopefully) not too much code here, and thus a re-generate of the events without a "very easy" to miss under score is what I suggest you try here.

    Just a quick look at above, I don't see anything much wrong, but I would try a re-gen of the events like I did as per that screen cap. (so, you hit ctrl-space when under the quotes (" ") to get that pop option to "create new event" as I did above.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.