首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Asp.net链接onRowCommand不工作

Asp.net链接onRowCommand不工作
EN

Stack Overflow用户
提问于 2014-02-06 14:23:16
回答 1查看 760关注 0票数 3

下面给出了我的GridView id,(应用程序的Asp.net web )

代码语言:javascript
代码运行次数:0
运行
复制
asp:GridView ID="grid"  runat="server" AutoGenerateColumns="false" Width="913px" ViewStateMode="Enabled" 
          ShowHeaderWhenEmpty="true" ShowHeader="true" onrowcommand="ContactsGridView_RowCommand" >

我的onRowCommand方法

代码语言:javascript
代码运行次数:0
运行
复制
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)
        {
        }

    }
}

但它碰到了一个错误

代码语言:javascript
代码运行次数:0
运行
复制
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?)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-06 14:26:30

如果要在后面的代码中运行ContactsGridView_RowCommand方法,则将其更改为publicprotected

代码语言:javascript
代码运行次数:0
运行
复制
protected void ContactsGridView_RowCommand

或者将该方法放在脚本标记中的页面上,它将按如下方式工作

代码语言:javascript
代码运行次数:0
运行
复制
<script runat="server">

  void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
   ...
  }
</script>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21605509

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档