Getting error in Gridview1

Compiler Error Message: BC30456: 'GridView1_RowCommand' is not a member of 'ASP.gridpage2_aspx'.

Source Error:

 

Line 8:  <body>
Line 9:      <form id="form1" runat="server">
Line 10:     <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#3366CC"
Line 11:         BorderStyle="None" BorderWidth="1px" CellPadding="4" AllowSorting="True" AutoGenerateColumns="False"
Line 12:         ShowFooter="True" OnRowCommand="GridView1_RowCommand;">
 

A red line was on Line10. Also why did it say gridpage2 and not Gridpage2
zachvaldezAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
Do you have the GridView1_RowCommand Sub in your code behind?

In your page directive name must be like  gridpage2
Easwaran ParamasivamCommented:
Remove the semicolon after GridView1_RowCommand.
Easwaran ParamasivamCommented:
Also make sure that GridView1_RowCommand is exists in the code behind file.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

zachvaldezAuthor Commented:
>>>Remove the semicolon after GridView1_RowCommand.  I placed that just to test it but it was getting same error without..
>>>Also make sure that GridView1_RowCommand is exists in the code behind file.
there is code there too.

I delete the Onrowcommand line in the source and it ran
Easwaran ParamasivamCommented:
Could you please share your code? The Onrowcommand should have some command name in any of the field in the GridView. Please refer the article: http://www.codeproject.com/KB/webforms/GridView_DropDownList.aspx
zachvaldezAuthor Commented:
>>>>gridpage2
Why did it required to be in lowercase since I created it as'Gridpade2?
Easwaran ParamasivamCommented:
Could you plz share your code? So that I can narrow down the problem.
zachvaldezAuthor Commented:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Gridpage2.aspx.vb" Inherits="Practice.Gridpage2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" AllowSorting="True" AutoGenerateColumns="False" ShowFooter="True" OnRowCommand="GridView1_RowCommand">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<RowStyle BackColor="White" ForeColor="#003399" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
<asp:TemplateField HeaderText="LastName">
<ItemTemplate>
<asp:Label ID="Label1" Text='<%# Eval("LastName") %>' runat="server"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<asp:TextBox ID="TextFirstName" runat="server"></asp:TextBox>
<asp:TextBox ID="TextTitle" runat="server"></asp:TextBox>
<asp:Button ID="Button1" CommandName = "ADD" runat="server"
Text="Add"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
    </div>
    </form>
</body>
</html>

>> Also ,I would like to add Firstname and Title in the Header and populate the grid as well but I dont know how to do that.


Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data
Public Class Gridpage2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindData()
        End If
    End Sub
    Private Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "ADD" Then
            Dim Lname As String = DirectCast(GridView1.FooterRow.FindControl("txtLastName"), TextBox).Text

            Dim Fname As String = DirectCast(GridView1.FooterRow.FindControl("TextFirstName"), TextBox).Text
            Dim Title As String = DirectCast(GridView1.FooterRow.FindControl("TextTitle"), TextBox).Text
            AddNewRecord(Lname, Fname, Title)
        End If
    End Sub
    Private Sub AddNewRecord(ByVal LN As String, ByVal FN As String, ByVal Title As String)

        Dim connectionString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString

        Dim myConnection As New SqlConnection(connectionString)

        Dim query As String = "INSERT INTO Employees(LastName,FirstName,Title) VALUES(@LN,@FN,@Title)"

        Dim myCommand As New SqlCommand(query, myConnection)

        myCommand.Parameters.AddWithValue("@LN", LN)
        myCommand.Parameters.AddWithValue("@FN", FN)
        myCommand.Parameters.AddWithValue("@Title", Title)

        myConnection.Open()

        myCommand.ExecuteNonQuery()

        myConnection.Close()

        BindData()

    End Sub

    Private Sub BindData()

        Dim connectionString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString

        Dim myConnection As New SqlConnection(connectionString)

        Dim ad As New SqlDataAdapter("SELECT EmployeeID, LastName,FirstName,Title FROM Employees", myConnection)

        Dim ds As New DataSet()

        ad.Fill(ds, "Employees")

        GridView1.DataSource = ds

        GridView1.DataBind()

    End Sub
End Class


Easwaran ParamasivamCommented:
Well. Change the Private Sub GridView1_RowCommand to Protected Sub GridView1_RowCommand  in your code behind file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zachvaldezAuthor Commented:
Hey! That was it!!. What's wrong with Private...?
Also How would I add the Header to display all fields In my Select ...?

It only took u less than 2 min. to figured that out!  BIG THANKS
Easwaran ParamasivamCommented:
If the method is private that won't be accesable from ASPX page.!

Please give the points to me :)
zachvaldezAuthor Commented:
Can u add the last request to this close post?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.