از آموزش فوق استفاده کردم اما زمانی که OnRowCommand را به GridView اضافه می کنم خطای زیر رو دارم :
Error 1 'ASP.default_aspx' does not contain a definition for 'OnRowCommand' and no extension method 'OnRowCommand' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) D:\Web-Design\More\Default.aspx 13
در DataTextField ابزار Button چه مقداری را باید وارد کنم؟!
کدهای دیزاین :
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnRowCommand="OnRowCommand">
<Columns>
<asp:ButtonField CommandName = "ButtonField" DataTextField = "am_id" ButtonType = "Button"/>
</Columns>
</asp:GridView>
</div>
</form>
سی شارپ :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=localhost; Initial Catalog=Home; Integrated Security=TRUE ");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select am_id as 'ردیف' , am_mantaghe as 'منطقه' , am_title_home as 'عنوان' , am_metraj as 'متراژ' , am_tabaghe as 'طبقه' , am_build_year as 'سال ساخت' , am_eghdam as 'اقدام' , am_price as 'قیمت کل' from T_Amlak where am_city= 'اهواز' ", con);
DataSet ds = new DataSet();
da.Fill(ds, "Temp");
GridView1.DataSource = ds;
GridView1.DataMember = "Temp";
GridView1.DataBind();
con.Close();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = GridView1.Rows[index];
}
}