【问题标题】:Asp.net Link onRowCommand not workingAsp.net Link onRowCommand 不起作用
【发布时间】:2014-03-03 13:15:04
【问题描述】:

下面给出的我的 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?)

【问题讨论】:

    标签: c# asp.net gridview webforms


    【解决方案1】:

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

    protected void ContactsGridView_RowCommand
    

    或者将页面上的方法放在脚本标签中,它会按原样工作

    <script runat="server">
    
      void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
       ...
      }
    </script>
    

    【讨论】:

      猜你喜欢
      • 2017-06-03
      • 1970-01-01
      • 2018-03-15
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      • 2010-12-02
      • 2016-04-15
      相关资源
      最近更新 更多