views:

174

answers:

5

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 BookStore();
        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!

A: 

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.

Andrey Tagaew
Tried it, exactly as shown in the following code: http://pastebin.com/H2kTTT3VHowever nothing changed.It seems that the event itself isn't fired for a reason.
iTayb
Can you show all codebehind code ?
Andrey Tagaew
Here is my codebehind code: http://pastebin.com/ShBtwGEuThank you very much.
iTayb
A: 

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.

Aristos
For some reason, the RowCommand event isn't fired as well. Nothing happens.
iTayb
did you place the OnRowCommand="RowCommand"
Aristos
Yes. Here is my updated aspx file: http://pastebin.com/dZL6Cjg4, my updated aspx.cs file: http://pastebin.com/Vz8Zxazw - RowCommand has no definition at the moment, but when I click the button, even the server.transfer method won't fire. that means that the event itself isnt fired. I really can't get what's the problem.
iTayb
@iTayb Very wired, because the RowCommand has no limitation, must be fire up.... very wired... tell me, when you click on the delete button did you see the page do post back, or not ? or nothing happens when you press the delete button ?
Aristos
Nothing happens.
iTayb
@iTayb oh, if nothing happends then the Validator blocking the submit. Add on all validators the validationgroup="InputGrp" well I guess - but there is no reason if you press the button, to not trigger the postback and the page reload, unless some javascript stop the form from submit.
Aristos
@iTayb I also notice one problem, the <form is not include all asp controls !!!! one asp:Hyperlink is out side the form !!!! Place form after the body, and close it after after your last center ! Place even this stop it from submit.
Aristos
@iTayb !!! I see one more serius, you have give the form a name !!!... remove it. only thr run= and the id=
Aristos
I don't have any validation control on the page. I've fixed the errors that you mentioned, but it didn't change a thing. I have another button on the page that do an postback. Perhaps something wrong with the delete buttonfield itself.
iTayb
A: 

XML is case-sensitive. So is ASP.NET. Make sure your attributes are correctly cased.

Alternatively, make sure your DataKey property is setup correctly.

leppie
What d'ya mean by datakey?
iTayb
A: 

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

Flatlineato
Still nothing happens.
iTayb
The page don't refresh? Or the event is not invoked?
Flatlineato
The page won't refresh. There is no postback.
iTayb
+2  A: 

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.

Flatlineato
That solved it! Man, you're a life saver.
iTayb
if you can use debugger instead of redirect and response.write :)
Flatlineato
I'd like to know: how did you realize that it breaks off the javascript code?
iTayb
I have debugged your page, finded the error raised from theForm.submit() and googled for the error, one of the page that i find report a problem with button with id=submit.If a page don't post back is often a javascript error
Flatlineato