3

my GridView id given below, (Asp.net web from application)

asp:GridView ID="grid"  runat="server" AutoGenerateColumns="false" Width="913px" ViewStateMode="Enabled" 
          ShowHeaderWhenEmpty="true" ShowHeader="true" onrowcommand="ContactsGridView_RowCommand" >

my method for onRowCommand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FirstWebForm.business_objects;

namespace FirstWebForm
{
    public partial class About : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grid.DataSource = dataaccess.Instance.getAll();
                grid.DataBind();
            }
        }

        void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
        {
        }

    }
}

But it hits a error enter image description here

Compiler Error Message: CS1061: 'ASP.about_aspx' does not contain a definition for 'ContactsGridView_RowCommand' and no extension method 'ContactsGridView_RowCommand' accepting a first argument of type 'ASP.about_aspx' could be found (are you missing a using directive or an assembly reference?)

1 Answer 1

1

Change the ContactsGridView_RowCommand method to be public or protected if it is to be ran in the code behind:

protected void ContactsGridView_RowCommand

Or put the method on the page in a script tag and it will work as is

<script runat="server">

  void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
   ...
  }
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.