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?
 
Easwaran ParamasivamCommented:
Well. Change the Private Sub GridView1_RowCommand to Protected Sub GridView1_RowCommand  in your code behind file.
0
 
Pratima PharandeCommented:
Do you have the GridView1_RowCommand Sub in your code behind?

In your page directive name must be like  gridpage2
0
 
Easwaran ParamasivamCommented:
Remove the semicolon after GridView1_RowCommand.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Easwaran ParamasivamCommented:
Also make sure that GridView1_RowCommand is exists in the code behind file.
0
 
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
0
 
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
0
 
zachvaldezAuthor Commented:
>>>>gridpage2
Why did it required to be in lowercase since I created it as'Gridpade2?
0
 
Easwaran ParamasivamCommented:
Could you plz share your code? So that I can narrow down the problem.
0
 
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


0
 
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
0
 
Easwaran ParamasivamCommented:
If the method is private that won't be accesable from ASPX page.!

Please give the points to me :)
0
 
zachvaldezAuthor Commented:
Can u add the last request to this close post?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.