RowsDeleting event doesn't fire
I have a gridview with a onrowdeleting="SellersGridView_RowsDeleting"
switch.
My method is:
protected void SellersGridView_RowsDeleting(object sender, GridViewDeleteEventArgs e)
{
string seller = ((Label)SellersGridView.Rows[e.RowIndex].Cells[0].FindControl("TextBoxSeller")).Text;
BookStore b = new BookS开发者_开发知识库tore();
b.LoadFromXML(Server.MapPath("list.xml"));
string ISBN = Request.QueryString["ISBN"].ToString();
int ID = b.BooksList.FindIndex(x => x.ISBN == ISBN);
Book myBook = b.BooksList[ID];
myBook.RemoveSeller(seller);
Response.Redirect("editbook.aspx?ISBN=" + ISBN);
}
Well, it seems that when I try to delete anything - nothing happens. I tried to change the first line to Response.Redirect("foo")
just to check if the event itself is fired, and it turns out that it doesn't. I can't get The reason.
Here is my gridview control: http://pastebin.com/CKDAMECT Here is my codebehind code: http://pastebin.com/ShBtwGEu
Thank you very much!
I find the problme you have a button whit ID="submit", this cause error in the javascript post back function theForm.submit(). Change the name and the page trigger postback.
XML is case-sensitive. So is ASP.NET. Make sure your attributes are correctly cased.
Alternatively, make sure your DataKey property is setup correctly.
After all talks, I see that the form is not include all asp.net controls. Please fix this.
Also you give the form a name !, only the **run=**server and the **id=**whatid. The name maybe block the correct submit data.
Second if not post back fires, then if not the problem is the form, then some javascript stop it from fire, maybe is the validation (I do not think so, but you never know).
So check the form for start. - Must include everything of asp.net.
If your page don't post back si possible that the gridview button cause validation of other controls? Try to change button field with template columns and linkbutton/immage button with causavalidation=false
It seems to me from your Page_Load code that you are binding the data to the GridView only one time - during first loading of the page. When postback is raising, the server does not remember about rows in your grid and can't fire processing of Deleting event.
Try to move the code
SellersGridView.DataSource = myBook.Sellers;
SellersGridView.DataBind();
out from if (!IsPostback)
section. In this case you will make your grid to be filled every time.
精彩评论