Baper
Baper

Reputation: 1543

Rowdeleting event doesn't fire

I have a gridview and I have a button on it.I want, if the user click on a button on a row,this row will be delted.I did this steps but I have no success.could you please help me to solve my problem?

 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int k=int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
            Label1.Text = k.ToString();
        }

I wanted to see the value in a lable but no success( I think this event doesn't fire)

Upvotes: 2

Views: 1368

Answers (2)

walther
walther

Reputation: 13600

Edited:

I like to specify my handlers in code-behind in Page_Init event, so it looks like this:

protected void Page_Init(object sender, EventArgs e)
{
   gw.RowDeleting += new GridViewDeleteEventHandler(gw_RowDeleting);
}

void gw_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
   // do whatever you want
}

Upvotes: 2

Kane
Kane

Reputation: 16802

I am assuming that your data is coming from a database, but you haven't specified in your sample code that you are calling the delete method in your data access layer / EF / repository.

Perhaps reading this tutorial will help? http://www.asp.net/web-forms/tutorials/data-access/editing,-inserting,-and-deleting-data/an-overview-of-inserting-updating-and-deleting-data-cs

Upvotes: 1

Related Questions