Reputation: 8849
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
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?)
Upvotes: 3
Views: 786
Reputation: 33306
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>
Upvotes: 1