下面给出了我的GridView id,(应用程序的Asp.net web )
asp:GridView ID="grid" runat="server" AutoGenerateColumns="false" Width="913px" ViewStateMode="Enabled"
ShowHeaderWhenEmpty="true" ShowHeader="true" onrowcommand="ContactsGridView_RowCommand" >
我的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)
{
}
}
}
但它碰到了一个错误
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?)
发布于 2014-02-06 14:26:30
如果要在后面的代码中运行ContactsGridView_RowCommand
方法,则将其更改为public
或protected
:
protected void ContactsGridView_RowCommand
或者将该方法放在脚本标记中的页面上,它将按如下方式工作
<script runat="server">
void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
...
}
</script>
https://stackoverflow.com/questions/21605509
复制相似问题