Click here to Skip to main content
15,895,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a problem in my code.
I always have an error.

Here is my code

<pre lang="xml"><asp:GridView ID="GridView1" runat="server"
              AutoGenerateColumns="False"
              DataKeyNames="ID"
              DataSourceID="SqlDataSource1"
              OnRowDeleted="GridView1_RowDeleted"
              OnRowUpdated="GridView1_RowUpdated"
              ShowFooter="true"
              OnRowCommand="GridView1_RowCommand">
<Columns>
    <asp:CommandField ShowDeleteButton="True"
                      ShowEditButton="True" />
    <asp:TemplateField HeaderText="ID" SortExpression="ID">
    <ItemTemplate>
    <asp:Label ID="lblID" runat="server"
                          Text='<%#Eval("ID") %>'>
    </asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:Button ID="btnInsert" runat="server"
                Text="Insert" CommandName="Add" />
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="FirstName"
                       SortExpression="FirstName">
    <ItemTemplate>
    <asp:Label ID="lblFirstName" runat="server"
               Text='<%#Eval("FirstName") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtFirstName" runat="server"
                 Text='<%#Bind("FirstName") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtFname" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="LastName"
                       SortExpression="LastName">
    <ItemTemplate>
    <asp:Label ID="lblLastName" runat="server"
               Text='<%#Eval("LastName") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtLastName" runat="server"
                 Text='<%#Bind("LastName") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtLname" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Department"
                       SortExpression="Department">
    <ItemTemplate>
    <asp:Label ID="lblDepartment" runat="server"
               Text='<%#Eval("Department") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtDepartmentName" runat="server"
                 Text='<%#Bind("Department") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtDept" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Location"
                       SortExpression="Location">
    <ItemTemplate>
    <asp:Label ID="lblLocation" runat="server"
               Text='<%#Eval("Location") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtLocation" runat="server"
                 Text='<%#Bind("Location") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtLoc" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConString%>"
DeleteCommand="DELETE FROM [Employees] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [Employees] ([FirstName],
[LastName],[Department], [Location])
VALUES (@FirstName, @LastName, @Department, @Location)"
SelectCommand="SELECT [ID], [FirstName], [LastName],
[Department], [Location] FROM [Employees]"
UpdateCommand="UPDATE [Employees] SET
[FirstName] = @FirstName, [LastName] = @LastName,
[Department] = @Department, [Location] = @Location
WHERE [ID] = @ID" OnInserted="SqlDataSource1_Inserted">

<DeleteParameters>
    <asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
    <asp:Parameter Name="FirstName" Type="String" />
    <asp:Parameter Name="LastName" Type="String" />
    <asp:Parameter Name="Department" Type="String" />
    <asp:Parameter Name="Location" Type="String" />
    <asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
    <asp:Parameter Name="FirstName" Type="String" />
    <asp:Parameter Name="LastName" Type="String" />
    <asp:Parameter Name="Department" Type="String" />
    <asp:Parameter Name="Location" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:Label ID="lblMessage" runat="server"
           Font-Bold="True"></asp:Label><br />






And the error is "it is not a member of 'ASP.default_aspx.'"
I hope you can help me.
Thanks a lot!
Posted
Updated 4-May-11 19:58pm
v2
Comments
Sandeep Mewara 5-May-11 2:15am    
There must be some event name before the error. What is not the member?
Share the complete error.
bsb25 6-May-11 4:41am    
give the full exception or the error part...we can't help without tat

Make sure that youre namespaces, classes and events are correctly named. Make sure that you have a GridView1_RowCommand in the code behind class in the right namespace. This is most probably the error.

It happens when you rename the name of the class or file and forget to also rename the class or vice versa.
 
Share this answer
 
Those are event handlers that don't exist in your code-behind file. You have to add them, and then it should be good to go.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900