?
Solved

Getting error in Gridview1

Posted on 2011-10-03
12
Medium Priority
?
587 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:zachvaldez
  • 6
  • 5
12 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36907829
Do you have the GridView1_RowCommand Sub in your code behind?

In your page directive name must be like  gridpage2
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36907836
Remove the semicolon after GridView1_RowCommand.
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36907838
Also make sure that GridView1_RowCommand is exists in the code behind file.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:zachvaldez
ID: 36907930
>>>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
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36907943
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
 

Author Comment

by:zachvaldez
ID: 36908943
>>>>gridpage2
Why did it required to be in lowercase since I created it as'Gridpade2?
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36909337
Could you plz share your code? So that I can narrow down the problem.
0
 

Author Comment

by:zachvaldez
ID: 36914616
<%@ 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
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 1400 total points
ID: 36914633
Well. Change the Private Sub GridView1_RowCommand to Protected Sub GridView1_RowCommand  in your code behind file.
0
 

Author Comment

by:zachvaldez
ID: 36914680
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
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36914686
If the method is private that won't be accesable from ASPX page.!

Please give the points to me :)
0
 

Author Closing Comment

by:zachvaldez
ID: 36914707
Can u add the last request to this close post?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question