tags:

views:

110

answers:

3

I’m getting this error over and over again.

Loading the data into the GridView works, but when I want to delete a row I'm getting that error.

<asp:GridView ID="OrdersGridView" runat="server" AutoGenerateColumns="False" onrowdeleted="OrdersGridView_RowDeleted">
    <Columns>
        <asp:TemplateField HeaderText="Product Name">
            <ItemTemplate>
                <asp:HiddenField runat="server" ID="HiddenField1" Value='<%#Eval("oid")%>'></asp:HiddenField>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="titel" HeaderText="Name" />
        <asp:BoundField DataField="oid" HeaderText="Itemno" />
        <asp:BoundField DataField="prijs" HeaderText="Price" />
        <asp:CommandField ButtonType="Link" CausesValidation="false" HeaderText="Update" ShowDeleteButton="True" />
        <asp:BoundField DataField="prijs" HeaderText="Subtotal" />
    </Columns>
</asp:GridView>

C# codebehind - I'm not really deleting the row from the database but it's a test:

protected void OrdersGridView_RowDeleted(object sender, System.Web.UI.WebControls.GridViewDeletedEventArgs e)
{
    if (e.Exception != null)
    {
        lblStatus.Text = e.Exception.ToString();
    }
    else 
    {
        string sValue = ((HiddenField)OrdersGridView.SelectedRow.Cells[1].FindControl("HiddenField1")).Value;
        lblStatus.Text = sValue;
    }
}

But after clicking, I get a bigass yellow page with the next error:

The GridView 'OrdersGridView' fired event RowDeleting which wasn't handled.

A: 

It looks like you are handling the "onrowdeleted" event, not the "RowDeleting" event

in your markup, change: onrowdeleted="OrdersGridView_RowDeleted"

to RowDeleting="OrdersGridView_RowDeleting"

Look a the docs for this event: you will also see that your handler's signature will need to change: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdeleting.aspx your new handler will look someting like this:

 protected void OrdersGridView_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e) { 
 if (e.Exception != null) { 
    lblStatus.Text = e.Exception.ToString(); 
   } 
   else 
   {
    string sValue = ((HiddenField)OrdersGridView.SelectedRow.Cells[1].FindControl("HiddenField1")).Value; lblStatus.Text = sValue; 
    } 
 }

the RowDeleting event happens, then the onrowdeleted event. The RowDeleting probally lets you Cancel the event.

brian chandley
I've changed it but it didnt work, I got the same error But I had the RowDeleting="OrdersGridView_RowDeleting" AND the RowDeleted="OrdersGridView_RowDeleted" at first and after reading about rowdeleting , I skipped that one cause I dont want to ask the user if he/she is okay with deleting the row, I just want to delete it.
Janis
The Grid View binds to data, and allows someone to delete a record: This event lets you tell the grid what *how* to do that. This error is saying "you have asked me to delete a record, but you have not told me how."the RowDeleted is slated after the delete happens.Can you indicate how it did not work (same error, different error, lblStatus.Text or sValue did not have the expected value)? thanks
brian chandley
its the same error on the same yellow colored error page , the error doesnt even show on my lblstatus label. Coould it somehow have something to do with me publishing the altered files to my host. I dont have the error on my local space.
Janis
The error does not happen locally? That is odd. does it behave as expected locally?.My first thought would be to check that both the aspx and the dlls have been published properly.
brian chandley
I only upload the aspx and the aspx.cs file, I didnt create dlls ... yet
Janis
If your aspx file use Inherits=<PageclassName> you need to deploy the dll for this fix to be fully deployed.
brian chandley
and uploading the Inherits=<.aspx.cs> is not enough ?I dont have individual .cs class files only aspx.cs files
Janis
I dont have a dll file
Janis
I see you are using dynamic compilation. (you have a App_Code folder and changes to your code behind files do not require a rebuild locally). If this is the case, a dll change is not required. I am not sure why you would see a diff locally and when you push this to a server.
brian chandley
A: 

Inside the if, set ExceptionHandled to true:

if (e.Exception != null)
{
    lblStatus.Text = e.Exception.ToString();
    e.ExceptionHandled = true;
}
Timwi
ok, but that doesnt help me with the error
Janis
A: 

anybody else a try ?

Janis